The client needs to restrict the selection of items based on the Billing Type selected on the sales order.
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/************************************************************************************************
* * Default the Resource Supply Item**
*
*
* **********************************************************************************************
*
* Author: Jobin and Jismi IT Services
*
* Date Created : 23-January-2024
*
* Created By: Athul Krishna, Jobin and Jismi IT Services
*
* Description : Restricting the other item selection while billing type is 'Time and Material'
*
* REVISION HISTORY
*
*
***********************************************************************************************/
define(['N/record'],
/**
* @param{record} record
*/
function(record) {
/**
* Validation function to be executed when sublist line is committed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
*
* @returns {boolean} Return true if sublist line is valid
*
* @since 2015.2
*/
function validateLine(scriptContext) {
try{
if(scriptContext.sublistId == 'item'){
var billingType = scriptContext.currentRecord.getValue({fieldId: 'custbody_jj_billing_type_so'});
var item = scriptContext.currentRecord.getCurrentSublistValue({sublistId: 'item',fieldId: 'item'});
console.log("billingType",billingType);
console.log("item", item)
if(billingType ==3 && item != 117){
alert(" Please note that you have chosen 'Time and Material' as the Billing Type.nKindly ensure that you select 'Resource Supply' as the item or update the Billing Type accordingly.")
return false;
}else{
return true;
}
}
return true;
}
catch(e){
console.error("error@validateLine",e)
}
}
/**
* Validation function to be executed when record is saved.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @returns {boolean} Return true if record is valid
*
* @since 2015.2
*/
function saveRecord(scriptContext) {
try{
var billingType = scriptContext.currentRecord.getValue({fieldId: 'custbody_jj_billing_type_so'});
console.log("billingType@save",billingType);
if(scriptContext.currentRecord.getValue({fieldId: 'custbody_jj_billing_type_so'}) == 3){
var length = scriptContext.currentRecord.getLineCount({sublistId: 'item'})
var lines=[];
for(var i=0; i< length;i++){
if(scriptContext.currentRecord.getSublistValue({sublistId: 'item',fieldId: 'item', line: i}) != 177){
lines.push(i+1);
}
}
if(lines.length>0){
alert("The Billing Type selected is 'Time and Material'.nKindly update the items in the following lines to 'Resource Supply' or modify the Billing Type accordingly.nLines : "+lines.join(','));
return false;
}else{
return true;
}
}
return true;
}
catch(e){
console.error("error@saveRecord",e)
}
}
return {
validateLine: validateLine,
saveRecord: saveRecord
};
});