Logic Hook: error 500 when create record from full form of subpanel

Goodmorning,
I have problem in my logic hook when create record from subpanel.
I have a subpanel in Accounts for my custom module.(one to many relationship)
In logic hook for my custom module, I use the id, of account record to made a query.
When I create a record (for my custom module) through the subpanel in Account module using the Full Form the bean value of the id contains the relationship link2 object rather than the related id string.

This causes a 500 error anytime and don’t create record. Can someone help me? Is there a workaround to fix this problem?

Thank you so much.
B.

Check your logs for more information. Here more information:

Thank you for your reply, but the problem is this:

In fact, in error.log file log, I have this error:

Recoverable fatal error:  Object of class Link2 could not be converted to string in /var/www/html/custom/modules/myModule/myModuleLogicHook.php on line 129.

At this line I use $bean->account_id_c that contains an id string when I create a record from module. But contain a Link2 object if I create a record from the subpanel of account module

You can test the variable type before using it, to accommodate both situations

https://www.php.net/manual/en/function.gettype.php

Thank you for your reply.
In your opinion, does this solution work?

$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;
}

It looks ok, but it’s too complex for me to be able to know if it’s going to work…

Why do you ask my opinion, when you can test it and ask SuiteCRM’s opinion? :stuck_out_tongue:

Correct… I try, and it works.
I ask for your opinion cause you know better than me, SuiteCRM, and I would like to have an opinion, if is a good solution or not…

1 Like