$ModuleObj = new {MODULE_NAME}(); $table_name = 'table_c'; $relate_values = array( 'fieldname1' => $bean->id ); $check_duplicates = true; $do_update = true; $data_values = array( 'fieldname1' => $bean->id, 'fieldname2' => $parent_id ); $ModuleObj->set_relationship($table_name, $relate_values, $check_duplicates, $do_update, $data_values);
where to put this code in sugarcrm
LikeLike
Where you are going to add the relationship. This code is to create a relationship between the modules dynamically.
LikeLike
Concerning this code it may function improperly if the user triggering this code does not have full access to the $meetings_id. You should add this line before the retrieve :
$meeting = new Meeting();
$meeting_user->disable_row_level_security = true;
$meeting->retrieve($meetings_id);
$meeting->parent_type = ‘Accounts’;
$meeting->parent_id = $accounts_id;
$meeting->save();
PS : Concerning this example it is probably useless but as the usage of the sugar’s method is good here, it might help if someone gets here and wants to copy / paste the code
LikeLike
Thanks phpbugs.
i understand for meetings, a flex relate field..maybe a sample with Accounts and Contacts?
i do not understand what i must fill in variable in :
$ModuleObj->set_relationship($table_name, $relate_values, $check_duplicates, $do_update, $data_values);
Regards
LikeLike
The relatonship with the Accounts and Contacts module can be dynamicallly set using this method. Please see the code below:
LikeLike
Hi,
thanks for all tips about SugarCrm. Really nice.
Can i ask something about set a relationship ?
can you give a sample about account and meetings with set a relationship code ?
Regards
LikeLike
The relationship between Accounts and Meetings module are quite different from other relationships. Here the parent_type method is used.
$meeting = new Meeting();
$meeting->retrieve($meetings_id);
$meeting->parent_type = 'Accounts';
$meeting->parent_id = $accounts_id;
$meeting->save();
Please check this code to attain the relationship.
LikeLike