Assigning Child Records In SugarCRM

If an account is assigned to another user, surely all the account’s contacts should also be reassigned. The same goes for other child records, such as documents, opportunities etc.

This requirement came up recently in the LinkedIn SugarCRM Network, so I thought I would put together a logic hook to see how it might be done.

The following logic hook was designed for Accounts, but could be applied to any module. Also I’ve specified in the code which child modules are to be updated. You may not need all related modules to be reassigned.

There are three issues that should be considered before implementing this type of logic, as follows.

(a) You will be saving related records, and if these have associated workflow or logic hooks, then these will get fired from this logic hook. You need to look carefully at each child module you use, just to be sure your are not going to initiate unwanted alters and actions.

(b) In some cases an account will have a huge number of records associated with it, and re-assigning them all via this logic hook could take some time. If this is the case it would be better to adopt a different solution (see below).

(c)  When a user creates a new contact, this logic hook will not ensure that the assigned user matches the account. This is because in this case the  accounts logic hook is never fired. To ensure all assignments are correct, you could also add logic hooks on each child module, or use a separate over-night process to ensure all records are assigned correctly (see below).

An alternative would be to run an overnight process to do the reassignments. This would involve similar logic, but run at a time of day that wouldn’t affect users. It would only look at recently updated records. This would handle (b) and (c) above, but not (a).

You will need to add the following to custom/modules/Accounts/logic_hooks.php

And add the following as a file custom/modules/Accounts/Reassign.php

 

I hope this is helpful. If you can suggest any improvements or have any comments, they would be very much appreciated.

Regards,

Greg