Requirement
While creating a sales order, if the sales team is empty, then show a pop-up message to notify that the sales team is empty and doesn’t allow the creation of a Sales Order record.
Solution
Create a client script and check if the sales team is empty in the Sales Order record. If the sales team is empty, then show a pop-up message and it will not allow the creation of a sales order.
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/currentRecord'],
/**
* @param{currentRecord} currentRecord
*/
function(currentRecord) {
/**
* Function to be executed after page is initialized.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
*
* @since 2015.2
*/
/**
* 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 currentRec=scriptContext.currentRecord
var sublistCount=currentRec.getLineCount({
sublistId:"salesteam"
})
if(sublistCount<1){
alert("Please enter a value for the sales team")
return false
}
return true
}
catch (e) {
console.log("error@saveRecord",e)
}
}
return {
saveRecord: saveRecord
};
});