Possible Sugar Bug:
Hi All,
I'm trying to make a custom field "total_number_c" required in Create view of Opportunity Revenue Line Item based on a field in Opportunity.
In the above image, you can see the "Total Number" is not a required field.
Following is what I have tried.
File Path:
src/custom/Extension/modules/RevenueLineItems/Ext/Vardefs/total_number_c.php
<?php
/**
* Total Number - custom db field
*/
$dictionary['RevenueLineItem']['fields']['total_number_c'] = array(
'audited' => true,
'calculated' => false,
'cols' => '',
'default' => '',
'dependency' => '',
'duplicate_merge_dom_value' => '0',
'duplicate_merge' => 'disabled',
'help' => '',
'len' => '255',
'massupdate' => false,
'merge_filter' => 'disabled',
'name' => 'total_number_c',
'no_default' => false,
'reportable' => true,
'required' => false,
'rows' => '',
'size' => '255',
'source' => 'custom_fields',
'studio' => 'visible',
'type' => 'varchar',
'unified_search' => false,
'vname' => 'LBL_TOTAL_NUMBER',
);
Note: The field is not REQUIRED for all the scenarios, So the dependency is achieved using "dependencies".
Create view Subpanel for Opportunity Revenue Line Item:
src/custom/modules/RevenueLineItems/clients/base/views/subpanel-for-opportunities-create/subpanel-for-opportunities-create.php
$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(
'total_number_c',
array(
'name' => 'assigned_user_name',
'enabled' => true,
'default' => true
)
)
),
),
);
Dependencies:
src/custom/Extension/modules/RevenueLineItems/Ext/Dependencies/managing_dep.php
$dependencies['RevenueLineItems']['managing_rules'] = array(
'hooks' => array("edit", "view"),
'trigger' => 'true',
'onload' => true,
'actions' => array(
array(
'name' => 'SetRequired',
'params' => array(
'target' => 'total_number_c',
'label' => 'LBL_TOTAL_NUMBER',
'value' => 'isInList(related($opportunities,"managing_c"),createList("one","two"))',
),
),
),
);
Scenario / Issue:
- Create an Opportunity and Fill the field "managing_c" with "one".
- The Total Number in Opportunity RLI should be required as per the Code, but this is not working in the Create view of the opportunity.
Workaround:
I have come up with a workaround for this issue. But I'm not satisfied with the approach. Is there any other way of doing it.
src/custom/modules/Opportunities/clients/base/views/create/create.js
({
extendsFrom: 'OpportunitiesCreateView',/**
* Override initialize
*
* @param options
*/
initialize: function (options) {
this._super('initialize', [options]);
this.model.addValidationTask('validateManagingDependencies', _.bind(this.doValidateManagingDependencies, this));
},/**
* Get the Line items model
*/
getRliModel: function() {
var rliContext = this.context.getChildContext({link: 'revenuelineitems'});
rliContext.prepare();
return rliContext.get('collection').at(0);
},doValidateManagingDependencies: function (fields, errors, callback) {
var rliModel = this.getRliModel();
var managingBusiness = this.model.get('managing_c');if (managingBusiness == "one") {
if (_.isEmpty(rliModel.get('total_number_c'))) {
var errorMessage = app.lang.get('LBL_TOTAL_NUMBER_REQUIRED', 'Opportunities');
// This below code is need to prevent the user from saving again
errors['total_number_c'] = {};
errors['total_number_c'].required = true;app.alert.show("opportunity_rli_errors", {
level: "error",
messages: errorMessage,
autoClose: false
});
callback(null, fields, errors);
}
}
}
})NOTE: A case was created for the Bug as well: SugarCRM