Make a quick vote 🗳 ️How do you refer to SuiteCRM extensions: add-ons or plug-ins? Click here to have your say 👈

How can I add more than one relationship in a hook?

after creating a relationship between contacts and calls I want to check if the unique code is present in other calls, if yes then I want to add those calls to the same contact too. How can I do it in code? Please help.

Hi @itsassef ,
could you please elaborate it a bit?
Do you want to SELECT all Calls with same Contact and…?

Anyway i’ll start searching here:

# Working with Beans

I want to attach a call with a contact and when I do that I want to check if this calls source_id matches with other past calls then those calls also should attach to this same contact. I’m using a hook “after relationship add” for this.
Getting full list of calls by source id then in a foreach I attach the calls to the contact. But it’s not working well.

Hi isassef

It might make it easier for people here to advise you - if you first gave details of what you are trying to achieve overall. Describe the ‘why’ of the need for the logic-hook.
eg ‘when user does X, I want Y to happen to object Z’

It may be that what you need is available ‘out of the box’ in Suite.

Your LogicHook code my looks like this one:


$sql = "SELECT id FROM calls WHERE source_id = '{$call->source_id}' AND id <> '{$call->id}' AND deleted = 0";
$res = $bean->db->query($sql, true);

while($row = $bean->db->fetchByAssoc($res)) $bean->calls->add($row['id']);

1 Like