Following is a code snippet to restrict the change of customer in sales order.
*/
function fieldChanged(scriptContext) {
const scriptObj = runtime.getCurrentScript();
const { currentRecord, fieldId } = scriptContext;
if (fieldId === 'entity') {
const entityId = currentRecord.getValue('entity');
const rejectionMessage = scriptObj.getParameter('custscript_csso_rejectmessage');
if (!isEmpty(entityId)) {
search.lookupFields.promise({
type: search.Type.CUSTOMER,
id: entityId,
columns: ['custentity_itg_disallow_create_order']
}).then(result => {
const customerStatus = result?.custentity_itg_disallow_create_order;
if (customerStatus) {
currentRecord.setValue('entity', '');
alert(rejectionMessage);
}
}).catch(reason => {
console.log('Failed reason', reason.message);
})
}
}
}