AnsweredAssumed Answered

Subpanel-for-create not populated

Question asked by Jeroen Somhorst on Jun 14, 2018
Latest reply on Jun 27, 2018 by André Lopes

Hi, 

 

I have created a link between Opportunities en a the products module. The idea is that when you create a new opportunity you directly can add the products that are needed (instead of using the revenue line items). Currently I have the subpanel for create working. It shows an empty line of product in a new opportunity. 

 

Now I want to prepopulate the opportunity and add at least 1 product record to this subpanel but I don't seem to get it working. 

 

the code for creating / showing the opportunity create view: 

 

let opp = app.data.createBean('Opportunities');
let parent = this.context.parent.attributes.model;

opp.set("account_id",parent.get('id'));
opp.set("account_name",parent.get('name'));
opp.set("assigned_user_name",parent.get("assigned_user_name"));
opp.set("assigned_user_id",parent.get("assigned_user_id"));
opp.set("name",this.generateName(productBrands,parent.get('name')));
opp.set("amount",turnover);
// fill data of model

let OpportunityContext = {
   module: 'Opportunities',
   model: opp,
   create:true,
   layout:"create",
   relatedRecords: selectedProducts,
   fromSubpanel: rawSelectedProducts.fromSubpanel || false,
   subpanelLink: 'opportunities_products_1'
};

app.controller.loadView(OpportunityContext);

the code that is inside the create:

<?php
/*
* Your installation or use of this SugarCRM file is subject to the applicable
* terms available at
* http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.
* If you do not agree to all of the applicable terms or do not have the
* authority to bind the entity as an authorized representative, then do not
* install or use this SugarCRM file.
*
* Copyright (C) SugarCRM Inc. All rights reserved.
*/
$viewdefs['RevenueLineItems']['base']['view']['subpanel-for-opportunities-create'] = array(
    'rowactions' => array(
        'actions' => array(
            array(
                'type' => 'rowaction',
                'css_class' => 'btn deleteBtn',
                'icon' => 'fa-minus',
                'event' => 'list:deleterow:fire',
            ),
            array(
                'type' => 'rowaction',
                'css_class' => 'btn addBtn',
                'icon' => 'fa-plus',
                'event' => 'list:addrow:fire',
            ),
        ),
    ),
    'panels' => array(
        array(
            'name' => 'panel_header',
            'label' => 'LBL_PANEL_1',
            'fields' => array(
                array(
                    'name' => 'product_template_name',
                    'enabled' => true,
                    'default' => true
                ),
                array(
                    'label' => 'LBL_LIST_NAME',
                    'enabled' => true,
                    'default' => true,
                    'name' => 'name',
                    'link' => 'true',
                ),
                array(
                    'label' => 'LBL_LIST_STATUS',
                    'enabled' => true,
                    'default' => true,
                    'name' => 'status',
                ),
                array(
                    'target_record_key' => 'account_id',
                    'target_module' => 'Accounts',
                    'label' => 'LBL_LIST_ACCOUNT_NAME',
                    'enabled' => true,
                    'default' => true,
                    'name' => 'account_name',
                ),
                array(
                    'target_record_key' => 'contact_id',
                    'target_module' => 'Contacts',
                    'label' => 'LBL_LIST_CONTACT_NAME',
                    'enabled' => true,
                    'default' => true,
                    'name' => 'contact_name',
                ),
                array(
                    'label' => 'LBL_LIST_DATE_PURCHASED',
                    'enabled' => true,
                    'default' => true,
                    'name' => 'date_purchased',
                ),
                array(
                    'label' => 'LBL_LIST_DISCOUNT_PRICE',
                    'enabled' => true,
                    'default' => true,
                    'name' => 'discount_price',
                ),
                array(
                    'label' => 'LBL_LIST_SUPPORT_EXPIRES',
                    'enabled' => true,
                    'default' => true,
                    'name' => 'date_support_expires',
                ),
            )
        ),
    ),
);

the controller is very simplistic. Only an extendsFrom: "SubpanelListCreateView" is specified. The question is now how I can add related products by javascript code.

Outcomes