salesagility / SuiteCRM

SuiteCRM - Open source CRM for the world
https://www.suitecrm.com
GNU Affero General Public License v3.0
4.47k stars 2.09k forks source link

Sub Panel Full Form Create Related ida Returns Link Object #5736

Open Jason-Dang opened 6 years ago

Jason-Dang commented 6 years ago

Issue

When creating a record through a subpanel using the Full Form for a custom one to many relationship, if there is a logic hook that uses the ida of the relate field for that relationship, the bean value of the id contains the relationship link2 object rather than the related id string.

Expected Behavior

Expect the ida for a relate field to always contain the id of the related record not the link object.

Actual Behavior

The value of the ida for a relate field is the link object rather than the id.

Possible Fix

Steps to Reproduce

  1. Create a one to many relationship through studio between two modules such as Accounts and Contacts so that one module gets a subpanel and the other a relate field.
  2. Create an after save logic hook for the module that has the relate field and apply a breakpoint.
  3. In the module that has the subpanel, create a record through the subpanel using the full form option ensuring that the relate field for the parent module you are creating from is populated.
  4. Save the record and inspect the value of the id for the relate field, it should contain the Link2 object instead of the id string.

Context

Causes a 500 error anytime you create a record through a subpanel using the full form if there is a logic hook that tries to retrieve a bean using the value of an ida field.

Your Environment

BeatriceFeltre commented 3 years ago

Good morning, I have the same problem, and solve in this way: Into my logic hook:

$myid= $bean->accounts_myModule_1accounts_ida; $account_id = null; if(is_object($myid) && $myid instanceof Link2){ $account_id = array_keys(myid->beans)[0]; } else { $account_id = $myid; }

Now, I can use $account_id like a string in a query. Hope this can help. Beatrice