AnsweredAssumed Answered

How do I use multiple flex relate fields in a custom module?

Question asked by Alx on Aug 8, 2014
Hi,

I am using Sugar 7.2.0 PRO.

I need to create a custom module with two flex relate fields.
Unfortunately, the Studio and the Module Builder don't allow more than one Flex Relate field (I reckon this is due to the 'parent_type' and 'parent_id' field names being hard-coded).

So I tried to create my own field type: I copied clients/base/fields/parent into custom/clients/base/fields/gauche_parent and replaced every occurence of 'parent_name' by 'gauche_parent_name' and every occurence of 'parent_id' by 'gauche_parent_id'.
Then I added my field definitions in custom/Extension/modules/dotb1_role/Ext/Vardefs/ :

$dictionary['dotb1_role']['fields']['gauche_parent_id']=
array(
'name'=>'gauche_parent_id',
'vname'=>'LBL_LIST_RELATED_TO_ID',
'type'=>'id',
'group'=>'gauche_parent_name',
'reportable'=>false,
'comment' => 'The ID of the parent Sugar object identified by parent_type'
);
$dictionary['dotb1_role']['fields']['gauche_parent_name']=
array(
'name'=> 'gauche_parent_name',
'parent_type'=>'dotb_role_parent_type_display' ,
'type_name'=>'parent_type',
'id_name'=>'gauche_parent_id',
'vname'=>'LBL_LIST_RELATED_TO',
'type'=>'gauche_parent',
'group'=>'parent_name',
'source'=>'non-db',
'options'=> 'dotb_role_parent_type_display',
'studio' => true,
);

$dictionary['dotb1_role']['fields']['gauche_parent_type']=
array(
'name'=>'gauche_parent_type',
'vname'=>'LBL_GAUCHE_PARENT_TYPE',
//'type' => 'gauche_parent_type',
'type' => 'parent_type',
'dbType'=>'varchar',
'required'=>false,
'group'=>'gauche_parent_name',
'options'=> 'dotb_role_parent_type_display',
'len'=>255,
'studio' => array('wirelesslistview'=>false),
);

I ran a Quick Repair And Rebuild and executed the suggested SQL queries.

Unfortunately, this is not working as expected: the field displays correctly in edit mode (I can choose the module from a dropdown and select a record) but, as soon as I hit the Save button, it is shown as if it were empty.

I have two options:
- I can either make this custom field type work (but I admit I don't know how to accomplish that)
- or I can find a way to add a second Flex Relate to my module. I saw that in 2012 SugarCRM's Community Manager John Mertic said it was possible through code (http://forums.sugarcrm.com/f6/multiple-flex-relate-fields-79012/), but I couldn't find how.

Could anyone please point me in the right direction?

Alexandre

Outcomes