AnsweredAssumed Answered

How to save relationship field in logic hook in Sugar 7

Question asked by Krishna Bhaya on Feb 22, 2014
Latest reply on Feb 25, 2014 by Kedar Gawande
Hi All,

I am using Sugarcrm 7.1.0 Enterprise edition.

I need to know how a relationship field can be updated in logic hook.

Explaining real scenario to make it clear.

1. Have a 'role_finance' field in custom relationship 'opportunity_contacts_1' .

2. It's visible in contacts subpanel of opportunity tab(recordview).

3. I need to set/update 'role_finance' field with value (it's a bool so need to set it to 1 or 0) when a new contact is created from subpanel or any existing contact is linked to opportunity.

4. Have added 'after_relationship_add' logic hook for the same with code for setting value of relationship field as 1 or 0.

I am getting contact bean in logic hook so tried to set relationship field value from here.

$contact_bean->opportunities_contacts_1_role_finance_c = 1;

But it's not working and not saving/updating relationship field value in  database with value.

Also tried to achieve this by manual update query ( opp_id and contact_id are related record ids )

UPDATE opportunities_contacts_1_c set op_role_finance_c = '1' where opportunities_contacts_1opportunities_ida = '<opp_id>' AND opportunities_contacts_1contacts_idb = '<contact_id>'

But it's too not working because when it's executed no relationship record is created in database for the same and thus update query will not work.

Not sure how we can update relationship field in bean or in link2 object so that it will be picked up while creating relationship record.

Please advice if any one has any idea about the same.

Thanks
Krishna

Outcomes