Fetch related bean's data before new record is saved

Hi,

I have the below scenario.
I created a custom module called “Demos”.
Then, I created a one-to-one relationship between “Demos” and “Accounts” modules.
When a user creates a new Demo record, I need to access some Account record’s fields
before the Demo record is saved.
The related account record’s fields will be used to populate some Demo record’s fields.

Approach 1:
I attached a “before_relationship_add” logic hook on Demo’s editview page.
Unfortunately, the above hook is called, after the Demo record is saved.
So, I cannot use it.

Approach 2:
I used javascript to listen to changes/clicks on ‘accounts_demos’ input field on Demo’s editview page.
Then, I would post an AJAX request to fetch related Account record’s fields.
Unfortunately, ‘accounts_demos’ input field is not fired when ‘accounts_demos’ popup closes (it fires send_back(…) function to set the field to editview page).

Can someone please provide a solution to the problem that I face?

Thanks in advance.

Hi,

Maybe with a before_save logic hook, http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.6/Logic_Hooks/Module_Hooks/

If you want the data before the Demo form appear, take a look at the controller.php of each module.

Hope that help.