Restrict the user from changing Price Level on Sales Order record after invoiced.

Scenario: In the sales order record, if the sublist value for the field ‘INVOICED’ is greater than zero, restrict the user from editing the sublist field value ‘Price Level’. Only allow the user to edit the ‘Price level’ if the field ‘INVOICED’ is Zero.

The Function to disable the price level field value is given below.

/**
     * The function used to restrict the modification of the value of the sublist field 'Sales Price' if the value of the sublist field 'INVOICED' is greater than 0
     * @param {*} scriptContext 
     */


    function disablePriceLevelIfInvoicedIsNotZero(scriptContext) {
      var currentRecordObj = currentRecord.get();
      var line = scriptContext.line;
      var invoicedValue = currentRecordObj.getSublistValue({
        sublistId: 'item',
        fieldId: 'quantitybilled',
        line: line
      });
      var priceLevelField = currentRecordObj.getSublistField({
        sublistId: 'item',
        fieldId: 'price',
        line: line
      });

      // Disable 'Price Level' field if 'Invoiced' value is not zero
      if (invoicedValue != 0) {
        priceLevelField.isDisabled = true;
      } else {
        priceLevelField.isDisabled = false;
      }
    }

This function will call from the ‘postSourcing’ entry point of the client script.

/**
       * Function to be executed when field is slaved.
       *
       * @param {Object} scriptContext
       * @param {Record} scriptContext.currentRecord - Current form record
       * @param {string} scriptContext.sublistId - Sublist name
       * @param {string} scriptContext.fieldId - Field name
       *
       * @since 2015.2
      */
      postSourcing: function (scriptContext) {
        var currentRecordObj = currentRecord.get();


        let recordType = currentRecordObj.type;
        let invoiced =  currentRecordObj.getCurrentSublistValue({
          sublistId: 'item',
          fieldId: 'quantitybilled'
      });
        if (recordType == RECORD_TYPE_SALES_ORDER && (mode == 'edit') && checkForParameter(invoiced) && (invoiced != 0)) {
          if (scriptContext.sublistId === 'item' && scriptContext.fieldId === 'price') {
            // Call the function to disable Price Level when Invoiced is zero for the selected line
            disablePriceLevelIfInvoicedIsNotZero(scriptContext);
          }
        }
      },

Leave a comment

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