New one-to-many relationship field not displaying after creation in before_save logic hook

I am populating a one-to-many relationship field (displays in the Detail view not in a sub-panel) in a before_save logic hook and the field will not display in the Detail View after the first display. I have to re-display the Detail view and the field is then populated. Is there a step that would allow this newly populated data to display the first time?

Thanks,
Dianna

I am not sure I understand what you’re doing, especially what is the sequence of events (populating, saving… what?).

But it sound like this isn’t something for a logic_hook (which isn’t strictly related to screen drawing, but to Beans), instead you should be overriding the display function on the View class of that Detail view.

Here’s a simple example to get you started

https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/15154-is-there-logic-hook-for-detailsview#50990

Thanks for the offer of assistance especially since I wasn’t very detailed about what I was doing. I did determine what I needed to do to get those fields to display by stepping through the debugger and seeing the information that was missing.
Thanks again,
Dianna

Ok, I’m glad you got it working.

If you think your working example can be useful for others, please post it here. I would like us to have more working code examples here on the forums. Thanks.

Yes, that’s a great idea, pgr!

I will explain how I got it to work, but since I could not find this information anywhere when searching for it, I don’t know if it is the “correct” way to do it. But it was a solution to my problem, so hopefully it might help someone else. First to explain the issue…

I have a custom module called 'Installations" which will be created when an Opportunity is Closed Won. We sell an item and we want to keep track of warranty information including serial number, product id etc and we will create an Installation to do this. So when an Opportunity is converted to an Installation, other information is transferred to the Installation related to the Opportunity and the example that I will use here is the Account. I want to create a one-to-many relationship between the Account and the Installation because an Account could have many Installations if we are fortunate and we sell them many items :slight_smile:

So I have created a before_save logic hook that will determine the Opportunity-to-Account relationship and use it to create a Account-to-Installation relationship and in my Installation DetailView, I have included the Account Name in the layout (not in a subpanel because there is only one Account related to the Installation). My code was creating the relationship correctly but upon initial display, the Account Name displayed blank. I was having to select and redisplay the Installation before the Account Name was populated. And then I populated the field but it was not a link (upon first display) which I did not like either. Through examining the variables in NetBeans, I was able to determine the fields that I needed to populated to get the Account Name to display as a link.

Code snippet…I have determined the Opportunity-related Account and its ID is in the variable $acc_id

//These next 5 lines are used to create the new relationship between the Account and Installation; there are many examples of how to do this on the internet
                 if ($bean->load_relationship ('accounts_installations_1')) {                      
                     $acc = new Account();                                                                           
                     $acc->retrieve($acc_id);
                     $bean->accounts_installations_1->add($acc); 
                      $bean->accounts_installations_1 = $acc->id;

//The next two lines were what I needed to make sure that my Detail View would display the Account correctly in the layout as a link
                     $bean->accounts_installations_1_name = $acc->name;
                     $bean->accounts_installations_1accounts_ida = $acc->id;   --this (...accounts_ida) is the name of the database field in the relationship table that identifies the account
                 }

Dianna

1 Like

Hi,

We are looking for the exact same functionality that you have mentioned. We also need to keep track of warranties after closing the opportunities and we also require the same one account to many item’s relationship.

Can you give us a detailed insight on how you achieved this. We are completely new to Suite CRM and are evaluating the same. Rest all seems fine except for this functionality.

Appreciate your help.

Hi @nileshv, welcome.

The techniques discussed here are described in the Developer Guide

https://docs.suitecrm.com/developer/

especially in the chapters about Beans and about Logic Hooks.