Related bean on a one to many relationship

I’ve made a custom module with a one to many relationship. I’m implementing a after_relationship_add logic hook were I would like to update a field with the sum of a integer field from all the related module. I can’t found how to get only the attribute of the related records. So far I can make the sum of all the records of the link module, but not the one that I’ve chose during the select in the subpanel on the detail view after a create.
here is what I’ve made :

public function totalSF($bean, $event, $arguments)
    {
        $relatedBeans = BeanFactory::getBean('ORD_Maintenance')->get_full_list();
        foreach ($relatedBeans as $relatedBean) {
            $bean->total_square_feet_c = $bean->total_square_feet_c + $relatedBean->square_feet;
        }
    }

I don’t fully understand your data structure, but instead of getting the full list, get just the related records of the bean that interests you.

See https://docs.suitecrm.com/developer/working-with-beans/#_related_beans

and try to use get_linked_beans()

1 Like

Thanks, I was using the wrong field name with get_linked_beans() my bad. Now it work!