LogicHooks

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

Parents
  • If I understand correctly, when on a given record you change the assigned user, you want to update all related records to have the same assigned user.

    The tricky part will be finding all the related records unless you list them explicitly in your logic hook.

    If you don't want to hardcode which children are reassigned you may have to iterate through all the "link" fields as suggested by  here:

    https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/423/find-all-records-related-to-a-specific-call-or-meeting

    Once you know the names of each link you can load the relationship between the $bean (your parent) and the linked module via the $link

    Fullscreen
    1
    2
    3
    4
    5
    6
    if($bean->load_relationship($link)){ //check the relationship exists
    foreach($bean->$link->getBeans() as $linkedBean){ //get the linked bean
    $linkedBean->assigned_user_id = $bean->assigned_user_id; //change the assigned user
    $linkedBean->save(); //save the linked bean
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    You may need to check the teams as well to make sure they are consistent with the new assignment.

    FrancescaS

Reply
  • If I understand correctly, when on a given record you change the assigned user, you want to update all related records to have the same assigned user.

    The tricky part will be finding all the related records unless you list them explicitly in your logic hook.

    If you don't want to hardcode which children are reassigned you may have to iterate through all the "link" fields as suggested by  here:

    https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/423/find-all-records-related-to-a-specific-call-or-meeting

    Once you know the names of each link you can load the relationship between the $bean (your parent) and the linked module via the $link

    Fullscreen
    1
    2
    3
    4
    5
    6
    if($bean->load_relationship($link)){ //check the relationship exists
    foreach($bean->$link->getBeans() as $linkedBean){ //get the linked bean
    $linkedBean->assigned_user_id = $bean->assigned_user_id; //change the assigned user
    $linkedBean->save(); //save the linked bean
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    You may need to check the teams as well to make sure they are consistent with the new assignment.

    FrancescaS

Children
  • I have created a building object and in Building object i have created Flat object . I have assigned a building to "km". my question is how to write logichooks through after_relationship_add ,  all flats of building assigned to same name km.