CoreBOSBB

Full Version: Create a second 'related user' field in a module
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Can I define a second 'related to user' field (UI type 53) in a module? Obviously not writing to the same column as 'assigned_user_id' but really as a normal module field.
you have to use uitype 101, there can only be one uitype 53 on a module, and there can only be one 101 also and it has to be defined like this:

https://github.com/tsolucio/corebos/blob/master/modules/CobroPago/manifest.xml#L456

I thnk the fieldname is important
Ah, Okay. In that case I will be kind of abusing this field, as I want to use it not to enter the user that needs to be reported to, but the user that is going to execute a certain salesorder in the field. But, at least I have the possibility to use this field.
It is just a name, so no problem. In fact we use it on the Payment module to indicate the sales person or responsable user of the payment
Ah, great. So I can use the field the way I have in mind. I'll write a little story on how I think I want to want my portal project to work as soon as I have all the info / testing I need.
I tried the following code to add a "101" field to SalesOrder:

PHP Code:
include_once('vtlib/Vtiger/Module.php');

$module Vtiger_Module::getInstance('SalesOrder');
$blockInstance Vtiger_Block::getInstance('LBL_SO_INFORMATION'$module);

$fieldInstance = new Vtiger_Field();
$fieldInstance->name 'reports_to_id';
$fieldInstance->table 'vtiger_salesorder';
$fieldInstance->column 'executing_user_id';
$fieldInstance->columntype 'INT(11)';
$fieldInstance->uitype 101;
$fieldInstance->typeofdata 'V~O';
$blockInstance->addField($fieldInstance); 

This worked, but gave me the following error:

PHP Code:
Catchable fatal errorObject of class Vtiger_Module could not be converted to string in index.php on line 687 

Does anyone know what went wrong? As said, the field was created.
What code is on that line? In a stock coreBOS there is just some CSS:

https://github.com/tsolucio/corebos/blob/master/index.php#L687

A few lines above there is $module=='Events', have you added some code there that assigns a Vtiger_Module to that variable?
The code on that line is:

PHP Code:
        preg_match("/^AddBlockFieldToDB/"$action) || 

I remember something happened: my PC crashed when this file was open in sublime text (I sometimes set the error reporting here for debugging). Now the entire file is double-spaced.. So I'll replace it with a stock one and see what happens.

Apart from that: what is the best way to delete a field? This way I can do some repeated tests and see if this is solved.
That line looks correct. Let me know how it goes.


To delete the field use the delete method


PHP Code:
$field Vtiger_Field::getInstance('your_field_name',$moduleInstance);
$field->delete(); 
Well, I've included that code in my postinstall, uninstalled and re-installed my module and the field is created. The install finishes without any issues. I'll update my code so that the correct removal methods for the field is implemented in the post uninstall.