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.