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’). For that, we have created a function to disable the sublist field ‘Price Leve’. We will disable the sublist field if the value of the sublist field ‘Invoiced’ is not equal to ‘0’.
The function 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(lineIndex) {
var currentRecordObj = currentRecord.get();
console.log('lineIndex', lineIndex);
var invoicedValue = currentRecordObj.getSublistValue({
sublistId: 'item',
fieldId: 'quantitybilled',
line: lineIndex
});
var priceLevelField = currentRecordObj.getSublistField({
sublistId: 'item',
fieldId: 'price',
line: lineIndex
});
// Disable 'Price Level' field if 'Invoiced' value is not zero
if (invoicedValue != 0) {
priceLevelField.isDisabled = true;
} else {
priceLevelField.isDisabled = false;
}
}
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))) {
disablePriceLevelIfInvoicedIsNotZero(lineIndex)
}
}