Pass value from Panel to related Subpanel when "create" is clicked on Subpanel

I have a custom Module (CLNTS_Clients) and a related custom Module (SVCS_Auth_Svcs). Both modules have a few of the same fields (name_tag, client_name, etc) and there is a 1:Many relationship.

How do I pass the name_tag value from CLNTS_Clients into the SVCS_Auth_Svcs when I click Create on the subpanel?

I have tried a few different ways I’ve seen but nothing seems to be working.

One practical way to solve your issue will be via Logic hook. Before save to be exact.
You can create a hook to populate the value to any field based on the related record. In fact you won’t need to display the fields on create from the subpanel. Fields need to be displayed on detail and list views only.

But I am needing the values to display when creating a record from the create button on the subpanel. Any ideas? Unsure if logic hook options would populate it.

Hi,

This functionality can be achieved by adding a populate_list array to the vardef of the SVCS_Auth_Svcs module.

Here is an example from the Accounts and Contacts module. In the contacts module vardef, a populate list is initialized which takes data from the fields of related and populates them into the fields of the current contact.

The keys in the populate list array specify the field names of the module whose data needs to be populated, and in the above example, it is the Accounts module and the values in the array specify the name of the fields where we want to populate the data. This can be customized as per requirements and in your case, the keys will be the name of the fields from CLNTS_Clients module and the values will be the name of the fields from SVCS_Auth_Svcs module.

1 Like

So I have tried the above solution, but when I do a rebuild/repair - it writes over the changes and resorts it back to the original file… This is in cache-modules-SVSC_Auth_Svcsvardefs.php. Should I be writing this within one of the custom files instead I’d assume? If so - which one please? This is driving me nuts how hard it is to pass a value from one module to another :expressionless: .

Thank you

ok so disregard that last portion - I found it in custom/extensions/modules/SVCS_Auth_Svcs/vardefs. I have modified the php file that shows the link between Clients (clnts_clients) and SVCS_Auth_Svcs, then I did a repair and rebuild.

This does push through to the other (module)vardefs.php files as you have shown in your example. I have checked the names of the fields to confirm in both of the modules here and I am still not seeing the data being populated when I click create on the SVCS_Auth_Svcs subpanel. It brings me to the full edit view of the SVCS_Auth_Svcs but the name tag field is blank still.

Any advice? Is it possible that with 8.1.0 there were changes that are causing this to not work as expected?

The above solution will work once you change the relate field. For example, if you want to create the record of SVCS_Auth_Svcs from module list and select clnts_clients. populate_list will then bring the data from clnts_clients and copy in the SVCS_Auth_Svcs record.

When you click on the create button from the subpanel, then clnts_clients is by default selected, so, populate_list functionality does not work. To achieve this, you need to create new custom SugarWidget for this subapnel. Please see the Account and Contact example in the following file for Suite 8:

public/legacy/include/generic/SugarWidgets/SugarWidgetSubPanelTopCreateAccountNameButton.php

I have attached the screenshot where it is copying the data from Account record and copies in the Contact create view.

Once the custom SugarWidget is added, then you need to add this custom SugarWidget in the subpanel metadata (Please see the highlighted code):

‘contacts’ => array(
‘order’ => 30,
‘module’ => ‘Contacts’,
‘sort_order’ => ‘asc’,
‘sort_by’ => ‘last_name, first_name’,
‘subpanel_name’ => ‘ForAccounts’,
‘get_subpanel_data’ => ‘contacts’,
‘add_subpanel_data’ => ‘contact_id’,
‘title_key’ => ‘LBL_CONTACTS_SUBPANEL_TITLE’,
‘top_buttons’ => array(
array(‘widget_class’ => ‘SubPanelTopCreateAccountNameButton’),
array(‘widget_class’ => ‘SubPanelTopSelectButton’, ‘mode’ => ‘MultiSelect’)
),
),

Please let me know if you have any question.

Thanks

I will test that path out, thank you for such detail!

Would making the custom widget in the above file path be upgrade safe or can I add an override into /custom/include/generic/SugarWidgets ?

ok so I have tried a couple ways here.
First - created in /custom/include/generic/SugarWidgets/SugarWidgetSubPanelTopCreateAuthServiceButton.php

<?php
if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}



class SugarWidgetSubPanelTopCreateAuthServiceButton extends SugarWidgetSubPanelTopButtonQuickCreate
{
    public function getWidgetId($buttonSuffix = true)
    {
        return parent::getWidgetId();
    }

    public function display($defines, $additionalFormFields = null, $nonbutton = false)
    {
        global $app_strings;
        global $currentModule;

        $title = $app_strings['LBL_NEW_BUTTON_TITLE'];
        //$accesskey = $app_strings['LBL_NEW_BUTTON_KEY'];
        $value = $app_strings['LBL_NEW_BUTTON_LABEL'];
        $this->module = 'SVCS_Auth_Svcs';
        if (ACLController::moduleSupportsACL($defines['module'])  && !ACLController::checkAccess($defines['module'], 'edit', true)) {
            $button = "<input title='$title'class='button' type='button' name='button' value='  $value  ' disabled/>\n";
            return $button;
        }
        
        $additionalFormFields = array();
        if (isset($defines['focus']->name_tag)) {
            $additionalFormFields['name_tag'] = $defines['focus']->name_tag;
        }
        /*
        if (isset($defines['focus']->billing_address_city)) {
            $additionalFormFields['primary_address_city'] = $defines['focus']->billing_address_city;
        }
        if (isset($defines['focus']->billing_address_state)) {
            $additionalFormFields['primary_address_state'] = $defines['focus']->billing_address_state;
        }
        if (isset($defines['focus']->billing_address_country)) {
            $additionalFormFields['primary_address_country'] = $defines['focus']->billing_address_country;
        }
        if (isset($defines['focus']->billing_address_postalcode)) {
            $additionalFormFields['primary_address_postalcode'] = $defines['focus']->billing_address_postalcode;
        }
        if (isset($defines['focus']->phone_office)) {
            $additionalFormFields['phone_work'] = $defines['focus']->phone_office;
        }
        */
        
        $button = $this->_get_form($defines, $additionalFormFields);
        $button .= "<input title='$title' class='button' type='submit' name='{$this->getWidgetId()}' id='{$this->getWidgetId()}' value='  $value  '/>\n";
        $button .= "</form>";
        return $button;
    }
}

Then in /custom/modules/CLNTS_Clients/metadata/subpaneldefs.php

<?php
$module_name = 'CLNTS_Clients';
$layout_defs[$module_name]['subpanel_setup']['securitygroups'] = array(
    'top_buttons' => array(
        array('widget_class'=>'SugarWidgetSubPanelTopCreateAuthServiceButton'),
        array('widget_class' => 'SubPanelTopSelectButton', 'popup_module' => 'SecurityGroups', 'mode' => 'MultiSelect')),
    'order' => 900,
    'sort_by' => 'name',
    'sort_order' => 'asc',
    'module' => 'SecurityGroups',
    'refresh_page' => 1,
    'subpanel_name' => 'default',
    'get_subpanel_data' => 'SecurityGroups',
    'add_subpanel_data' => 'securitygroup_id',
    'title_key' => 'LBL_SECURITYGROUPS_SUBPANEL_TITLE',
);

I then went into one of our clients, to the subpanel for SVCS_Auth_Svcs and clicked the Actions drop down - create.

name_tag did not pull over to the SVCS_Auth_Svcs screen from the create. I did also try placing the Widget file in the /include/generic/SugarWidgets folder… I did a rebuild and repair after as well.

Is there any syntax issue here, or logic issue? the CLNTS_Clients is a 1:M to the SVCS_Auth_Svcs module, I did notice that the Accounts:Clients is M:M so I’m unsure if that is causing a different reaction here.

I have also read that the Subpanel create follows the QuickCreate process (and doesn’t access pre-display and some other things - not fully applicable here), but should I be doing an over ride on the SugarWidgetSubPanelTopButtonQuickCreate.php instead?

@jkortus1234 did you ever solve this? I have a similar problem where when a task is created from the quote I want to populate the account name in the task. This works fine in editview and it works fine in quickedit as long as the quote is selected first. However, if the quote is auto populated in the task subpanel quick create (when you create it there) it does not get populated. I tried a bunch of strategies I found by Googling but nothing seemed to work.

Hey pstevens,

Its been a while on that one. What i think i did was an after save logic hook on the child/newly created record and then just used the get related beans to get the record it was created from and pulled the fields.

I did notice some oddities on 8.x.x… but this path should still work. Otherwise a scheduled job for clean up.

Thanks @jkortus1234 I have that setup with an after save logic hook to populate it. However, I’d really like it to show on the front end before save. I spent all day on it yesterday trying different things. I can get it to auto populate if I re-select the quote, it will populate the account in the subpanel task creation via the quicksearch. However, no matter what I try I just can’t get it to populate at the start when you create the task. It has to be possible, the quote is pre-populated! If I have time today I’m going to try and explore a JavaScript solution. All the PHP strategies I tried didn’t work. I can’t even get them to execute when the taks quick create is loaded.