Relationship sequence in Create and Update

Hi all,

I am using SugarCRM Enterprise, Version 8.3.0 (Build 149) (Winter '19).

I have developed custom action for workflow which contain following code.

if ($opportunityBean->load_relationship('contacts')) {
     // $bean is object of Meeting
     $load = $bean->load_relationship('contacts');
     
     // I have concern about this line
     $guestContacts = $bean->contacts->get();
     
     $opportunityBean->contacts->add($guestContacts[0]);
}

I want to grab contact from Meetings record and attach them to Opportunities record. The contact I want to grab is from Guest Panel of Meeting module.

The above code working when I am creating the record, but not working when I update the record.

I am getting Guest Panel contact when I am creating record first time. But If I update the record, I am not getting newly added Contacts in Guest Panel.

Scenario to populate this issue:

  1. Create Meeting without adding any contact in Guest Panel.
  2. Now Edit it.
  3. Add a contact in Guest Panel, click Save.
  4. On save, I am getting empty array in $guestContacts.

Question:

Is there any difference in sequence of adding related records in Create & Update?

How can we resolve this?

Sequence of execution I have understand in sugar as follows:

when I was working with logic hooks.

1. before_save logic hook

2. save record

3. after_save logic hook

4. before_relationship_add hook

4. added related records

5. after_relationship_add hook

I have to create an automated opportunity and have to grab some information from contact which is added as a Guest.

Parents Reply Children
  • Hi, André Lopes,

    I gone through logic hook, but I am using Advance workflow to achieve the task. I have created custom action for it.

    The same thing working when Create Record. But not working when Update Record.

    I want to achieve it in same code.

  • Hi Kishor,

    First of all sequence of execution of logic hook is:

    1. before_relationship_add hook

    2. added related records

    3. after_relationship_add hook

    4. before_save logic hook

    5. save record

    6. after_save logic hook

    Above is the execution whenever you  create a record via a subpanel of a module.

    I don't know what will the flow in the case whenever record is linked via Guest panel. I think in the Guest panel case, your listed sequence is correct that is why whenever you firstly create and then add the contacts then according to your sequence save hook is called before adding the relationships. that is why you can't able to get the contacts.

    I think you must implement your logic after "after relationship add" logic hook. May be it will work.