logic hook for when a user is assigned to a record

Hello

I want to trigger an action when a new user gets assigned to a record (by default it's assigned to "admin"). I'm trying the after_relationship_add hook, but it's not working.

Should I even be using the "after_relationship_add" hook at all? It looks like the user, is just a field and is not related to the "user" module... So if we assign a user to a record, is that considered as a relationship adding?

Registered it using:

$hook_array['after_relationship_add'] = Array();
$hook_array['after_relationship_add'][] = Array(
77,
'changes status of inventory unit when a new user gets assigned',
'custom/inventory/relationship_check_c.php',
'relationship_check_c',
'relationship_check_c');

And the hook code is:

class relationship_check_c {
   
    function relationship_check_c($bean, $event, $arguments) {

        $GLOBALS['log']->info('Executed relationship_check_c logic hook');

    }

}
  • 'assigned_user_id' are module fields, not relationships.  You will want to use a combination of a before and after save hook as not to incur a save loop.  

    function before_save_method($bean, $event, $arguments)
              {
                   //store as a new bean property
                   $bean->stored_fetched_row_c = $bean->fetched_row;
                   
                   
              }

    function after_save_method($bean, $event, $arguments)
              {
                   if (isset($bean->stored_fetched_row_c)&& $bean->stored_fetched_row_c['assigned_user_id'] != $bean->assigned_user_id)
                             {
                                  // do some stuff
                             }
              }