AnsweredAssumed Answered

Replacing a Relationship in Code Not Working

Question asked by Arthur Chocholacek on Nov 9, 2015
Latest reply on Nov 11, 2015 by Alan Beam

Hi Folks. Tearing what little hair I have left out over a seemingly nonsensical bug that I cannot figure out.

 

Perhaps the problem is me, so I come to you for help.

Install is Sugar 7.6.1.0 on Prem.

 

We have a heavy duty custom EditView page that is supposed to replace relationships if the field is changed, yadda yadda yadda. My code to do so is as follows

 

// Load the Relationship
$oppBean->load_relationship('accounts');

// Delete the relationship for each related account
foreach ($oppBean->accounts->getBeans() as $relBean) {
               $oppBean->accounts->delete($oppBean->id,$relBean->id);
}

// Display the related records, which you would expect to be nil, but instead it outputs the id of the original related record.
foreach ($oppBean->accounts->getBeans() as $relBean) {
                error_log(" PostDel Now Reld to: "  . $relBean->id);
}

// Add the new related account
 $oppBean->accounts->add($account_id);

// Display the new list of related records, which should only be the one we just added, but instead it outputs the ID of the original related record.
foreach ($oppBean->accounts->getBeans() as $relBean) {
error_log("Now Reld to: "  . $relBean->id);
}

 

If there's no existing Opp->Account relationship, it updates fine, but if there's an existing one, it behaves as above.

 

What am I missing? What am I doing wrong? I've done the same thing elsewhere and it works fine. Suggestions? Places to look? Common gremlins? Help!

 

-arthur

Outcomes