LogicHooks

What is the subquery to assigned user id in child object same as parents object through logic hooks?

Parents Reply Children
  • What Dmytro is proposing to you is to sell you a third party visual tool that builds the code of the logic hook for you. If you are not keen on coding that may be a solution for you.

    So, let's assume that you are looking for a code solution, which in this case is not hard to do.

    the trick with after_relationship_add logic hooks is that they provide you all the information for both the current bean (the record you are on when the the hook is triggered) and the related bean (the record to which you are relating your current record)

    As you can see here:
    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_11.0/Architecture/Logic_Hooks/Module_Hooks/after_relationship_add/
    the related_module will tell you what type of record you are relating the current record to

    and the related_id will tell you the ID of that record.

    This means you can use the BeanFactory 

    support.sugarcrm.com/.../

    to get the full bean, which will contain the information you need: the assigned_user_id, and use it to assign the Flat to the correct user.

    In your logic hooks on the Flat module, in the after_relationship_add you can do as follows:

    function flatAssignedUser($bean, $event, $arguments){
    
      //check if the Flat was just related to a Building by checking the related module name
    
      if($arguments['related_module'] == 'Buildings'){
    
        //get the Building information
    
        $buildingBean = BeanFactory::retireveBean('Buildings', $arguments['related_id']);
    
         //double check that you have a building bean
    
         if(!empty($buildingBean)){
            //copy the assigned user from the buildingBean to the bean (the Flat) and save
    
            $bean->assigned_user_id = $buildingBean->assigned_user_id;
    
            $bean->save();
    
         }
    
      }
    
    }

    I hope you find this helpful.

    FrancescaS