before_save get data from linked parent

Hello everyone,

new day, new problem :pinch:

I’ve got following modules:


Contacts
     |
      ____ Custom1
                    |
                    _____ Quotes

I’m creating a new quote with the subpanel in “Custom1”.
Therefore I created a logic hook in AOS_Quotes to load the contact id and to store it in the quote.

The logic hook is getting triggered, but I simply do not now how to get any further…


if (empty($bean->contact_id_c))
{
	//Contact empty, get contact 
	if ($bean->load_relationship('fthue_vorgaenge_aos_quotes'))
	{
             // ?????
             // $bean->contact_id_c = $bean->fthue_vorgaenge->contact_id_c
         }
}

Or do I also have to get the relation between “Custom1” and “Contacts”?
The documentation is unfortunatly not very helpful at this point.

Can I use relations at this point, or should Use after_save? Or is the ID for my “Custom1” module in the passed $arguments?

I managed to do this using the Workflow, but only after the record already was created and I hit “save” for the second time. (Set to work on “New records”) Probably beacause the link wasn’t working yet?

Any help would be greatly appreciated.

Kind Regards
Flying Dutchman

If anyone needs something like this. Here is my solution:


<?php

if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
   
    class before_save_class
    {
        function before_save_method($bean, $event, $arguments)
        {
			if ($bean->load_relationship('contacts') && count($bean->contacts->get()) == 0)
			{
				if ($bean->load_relationship('fthue_vorgaenge_aos_quotes'))
				{
					$vorgangBean = BeanFactory::getBean('FTHUE_Vorgaenge', implode($bean->fthue_vorgaenge_aos_quotesfthue_vorgaenge_ida->get()));
					if ($bean->load_relationship('contacts'))
					{
						$bean->contacts->add($vorgangBean->fthue_vorgaenge_contactscontacts_ida);
					}
				}
			}
			else
			{
				//Nothing to do
			}
        }
    }
?>
1 Like