Devyani Jain
07/10/2023, 6:56 AMbattk
07/10/2023, 7:09 AMbattk
07/10/2023, 7:10 AMDevyani Jain
07/10/2023, 7:10 AMDevyani Jain
07/10/2023, 7:11 AMbattk
07/10/2023, 7:12 AMbattk
07/10/2023, 7:13 AMDevyani Jain
07/10/2023, 7:13 AMDevyani Jain
07/10/2023, 7:14 AMDevyani Jain
07/10/2023, 7:14 AM/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
* @NmoduleScope SameAccount
*/
define(['N/record'], function (record) {
function myBeforeSubmit(scriptContext) {
var newRecord = scriptContext.newRecord;
//check if subtotal is greater than 100
var subtotal = newRecord.getValue({
fieldId: 'subtotal',
});
if (subtotal > 100) {
throw 'Confirm transaction amount greater than 100 bucks'; //throw the explicit error
log.debug({
title:'transaction subtotal',
details: 'transaction subtotal exceeds 100 bucks'
});
return false; // prevent the transaction from being saved
}
var customerId = newRecord.getValue({
fieldId: 'entity'
});
var customerObj = record.load({ //lookup , credit limit column
type: newRecord.Type.CUSTOMER,
id: customerId
});
var customerCreditLimit = customerObj.getValue({
fieldId: 'creditlimit'
});
var transactionTotal = newRecord.getValue({ // it should be transaction total or only total ? or customer balance ?
fieldId: 'total'
});
if (transactionTotal > customerCreditLimit) {
throw 'Order amount exceeds credit limit';
log.debug({
title:'order total',
details: 'Transaction total ('+ transactionTotal+') exceeds credit limit('+ customerCreditLimit +')'
});
return false; //prevent the transactionfrom being saved
}
return true;
}
return {
beforeSubmit: myBeforeSubmit
};
});
battk
07/10/2023, 7:16 AMbattk
07/10/2023, 7:17 AMbattk
07/10/2023, 7:18 AMbattk
07/10/2023, 7:21 AMvar subtotal = newRecord.getValue({
fieldId: 'subtotal',
});
if (subtotal > 100) {
throw 'Confirm transaction amount greater than 100 bucks'; //throw the explicit error
log.debug({
title:'transaction subtotal',
details: 'transaction subtotal exceeds 100 bucks'
});
return false; // prevent the transaction from being saved
}
looks fine for the subtotal requirementbattk
07/10/2023, 7:22 AMlog.debug({
title:'transaction subtotal',
details: 'transaction subtotal exceeds 100 bucks'
});
return false; // prevent the transaction from being saved
doesnt actually do anythingbattk
07/10/2023, 7:22 AMbattk
07/10/2023, 7:22 AMbattk
07/10/2023, 7:22 AMDevyani Jain
07/10/2023, 7:23 AMbattk
07/10/2023, 7:26 AMbattk
07/10/2023, 7:27 AMDevyani Jain
07/10/2023, 7:28 AMbattk
07/10/2023, 7:37 AM