Set QLI Field ReadOnly but not working in Create View

Hi All,

I'm trying to display a custom product field in QLI, So I made necessary changes. This particular field "total_number_c" should be a ReadOnly in QLI, So I made the following change:

src/custom/modules/Products/clients/base/views/quote-data-group-list/quote-data-group-list.php

array(
      'name' => 'total_number_c',
      'readonly' => true,
      'label' => 'LBL_TOTAL_NUMBER',
),

 src/custom/Extension/modules/Products/Ext/Vardefs/total_number_c.php
<?php
/**
* Total Number - custom db field
*/

$dictionary['Product']['fields']['total_number_c'] = array(
    'audited'                   => true,
    'calculated'                => false,
    'cols'                      => '',
    'comments'                  => 'Total Number',
    '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',
);

Dependencies: 

Note: This issue is not occurring if we remove the dependencies below.

src/custom/Extension/modules/Products/Ext/Dependencies/magaging_business_rules.php

<?php
$dependencies['Products']['magaging_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($quotes,"managing_c"), createList("one","two"))',
                                       ),
                                  ),
                                 array(
                                       'name' => 'SetVisibility',
                                       'params' => array(
                                             'target' => 'total_number_c',
                                             'label' => 'LBL_TOTAL_NUMBER',
                                             'value' => 'isInList(related($quotes,"managing_c"), createList("one","two"))',
                                       ),
                                 ),
               ),
);

With the above changes, the field is ReadOnly in Quote Record view / Edit View but during Quote create the field changes to an editable field. Refer to the image below.

Quote Edit View:

Quote Edit View

Quote Create View:

Quote Create View

If the QLI was a subpanel I could create a create-view-subpanel to solve this issue, but I'm not sure how to make the field read-only.

  • Hi Aravind Kumar,

    You have used related() function - related($quotes,"managing_c"),  to get value from parent quote but in create view, relationship not yet exists between quote and the QLIs hence this formula might not work.

    You might need to find some other way for this comparison, maybe can extend quote-data-group-list controller.

    Let us know how it goes.

    Regards.

  • Hi hats,

    Do you know, how can we get Line Item field value in `create.js`? I can write an `addValidationTask` and validate the field is not null.

  • Hi Aravind Kumar,

    Why not validate model at line item level? You can easily get value of parent quote model from "this.context.parent".

    Is there any specific reason you wanted to extend Quote create view rather than QLI quote-data-group-list?

  • Hi hats,

    The problem with that is, I'm trying to validate the line items in Quote Save since some of the fields need to be validated with respect to quote fields. Also, I'm trying to do that in Create view and `quote-data-group-list` doesn't work with validation in create view. Did you try before? 

  • Hi hats,

    Do you have a sample code for it? i cant find a sample to extend the create view of Quote `quote-data-group-list` ?

  • Found a Solution for the Create view: instead of making it read-only I added validation to make the field not null, so this is going to prevent from being null in my case.

    Fine Change:

    src/custom/modules/Quotes/clients/base/views/create/create.js

    /**
    * Override initialize
    *
    * @param options
    */
    initialize: function (options) {
          this._super('initialize', [options]);
          this.model.addValidationTask('validateManagingDependencies', _.bind(this.doValidateManagingDependencies, this));
    },

    doValidateManagingBusinessDependencies: function (fields, errors, callback) {
          var bundles = this.model.get('bundles');
          var productBundleItems;

          if (bundles && bundles.length) {
                _.each(bundles.models, function (bundleModel) {

                      // get the bundle items for this bundle to validate later
                      productBundleItems = bundleModel.get('product_bundle_items');

                      // loop through each product_bundle_items Products/ProductBundleNotes bean
                      if (productBundleItems.length != 0) {
                               _.each(productBundleItems.models, function (pbModel) {
                                        if (!pbModel.attributes.total_number_c) {
                                              

                                              // Do the Validation here
                                              var errorMessage = app.lang.get('LBL_TOTAL_NUMBER_REQUIRED', 'Quotes');
                                              app.alert.show("opportunity_rli_total_number_errors", {
                                                    level: "error",
                                                    messages: errorMessage,
                                                    autoClose: false
                                              });
                                        callback(null, fields, errors);
                                        }
                               });
                      }
             });
          }
       callback(null, fields, errors);
    },

    The above solution work as expected, refer validateBundleModels in `src/modules/Quotes/clients/base/views/create/create.js` to improve more on the solution.