Enable Sublist Field based on the conditions.

Scenario: The user needs to disable the Sublist field value of the field ‘Price Level’ if the invoice is billed (the value of the sublist field ‘Invoiced’ is equal to ‘0’).

The script will disable the column based on the condition by getting the sublist field and making it disabled using,

var priceLevelField = currentRecordObj.getSublistField({
    sublistId: 'item',
    fieldId: 'price',
    line: lineIndex
   });
 priceLevelField.isDisabled = true;

While using this code, the entire column ‘Price Level’ will be disabled.

So if the user selects the new line after disabling the ‘Price Level’ field, the user cannot edit/provide any values in the ‘Price Level’ sublist field. So, we have designed another function to enable the sublist field ‘Price Level’ by fetching the previous/next line.

The function is given below,

    /**
     * The Function is to enable the price level sublist field if the user select the new line. 
     * If the line is new line, then enable the sublist field by getting sublist field of the previous line or the next line
     * @param {*} lineIndex 
     */

    function enablePriceLevelForNewLine(lineIndex) { 
      try
      {
        var currentRecordObj = currentRecord.get();
        console.log('lineIndexnewlineline', lineIndex);
        let lineNumber = ''
        if(lineIndex === 0){
          lineNumber = lineIndex + 1;
        } else {
          lineNumber = lineIndex - 1;
        }
        console.log('lineNumberlineNumber', lineNumber);
  
        var priceLevelField = currentRecordObj.getSublistField({
          sublistId: 'item',
          fieldId: 'price',
          line: lineNumber
        });
        console.log('priceLevelFieldpriceLevelField', priceLevelField);
          priceLevelField.isDisabled = false;
      }
      catch(err)
      {
        console.error('error@enablePriceLevelForNewLine')
      }
      }

call this function from the lineInit entry point of the client script.

 lineInit: function (scriptContext) {
 if(recordType == RECORD_TYPE_SALES_ORDER && (mode == 'edit') && !checkForParameter(invoiced) && ((currentUserRole != ADMINISTRATOR) && (currentUserRole != AHA_CHIEF_FINANCIAL_OFFICER) && (currentUserRole != AHA_ACCOUNTING_MANAGER))){
          enablePriceLevelForNewLine(lineIndex);
        }
}

Leave a comment

Your email address will not be published. Required fields are marked *