This is m logic hook After Save
, this logic hook is perfectly working on my local machine.
But it is not working on sandboxcopy. I asked this question to Sugar Support team ,
They found that Set_relationship is not working .
But my question is why this is working on local or is there any alternate way to write this code, where i am wrong ?
class RHLogicHook {
function ReportingTeam($bean, $event, $arguments) {
if (isset($arguments['isUpdate']) && $arguments['isUpdate'] == false) {
$reporting_head = BeanFactory::retrieveBean('Contacts', $bean->contact_id_c);
$contact = BeanFactory::retrieveBean('Contacts', $bean->contacts_rh_reporting_head_1contacts_ida);
$reporting_team = new RH_reporing_team();
$reporting_team->contact_id_c = $contact->id;
$reporting_team->save();
$dataset = array(
'contacts_rh_reporing_team_1contacts_ida' => $reporting_head->id,
'contacts_rh_reporing_team_1rh_reporing_team_idb' => $reporting_team->id,
);
$reporting_team->set_relationship('contacts_rh_reporing_team_1_c', array(), false, false, $dataset);
}
}
}
Please help me out.
please dont use above . use load relation and add method .
class RHLogicHook {
function ReportingTeam($bean, $event, $arguments) {
if (isset($arguments['isUpdate']) && $arguments['isUpdate'] == false) {
$reporting_head = BeanFactory::retrieveBean('Contacts', $bean->contact_id_c);
$contact = BeanFactory::retrieveBean('Contacts', $bean->contacts_rh_reporting_head_1contacts_ida);
$reporting_team = new RH_reporing_team();
$reporting_team->contact_id_c = $contact->id;
$reporting_team->save();
$GLOBALS['log']->log('zob_ms_bean ' . print_r($reporting_head, 1));
if ( $reporting_head->load_relationship('contacts_rh_reporing_team_1')) {
$reporting_head->contacts_rh_reporing_team_1->add($reporting_team->id);
}
}
}
}
some of the functions are blacklisted, if thats the case you can easily use a trick to make sure that your code works great on production instance.Try below mentioned trick:
$hack_function="set_relationship"; $reporting_team->$hack_function('contacts_rh_reporing_team_1_c', array(), false, false, $dataset);
lets hope this solves your issue.