Imagine a scenario where your sales team frequently applies manual discounts on Sales Orders, but sometimes these exceed company policy limits. Such errors can directly impact profit margins and go unnoticed until after invoicing.
To address this, we can use a NetSuite User Event Script to automatically validate discounts before saving the record. The script ensures that no line item discount exceeds 20% of the item’s rate — providing real-time control and reducing manual review effort.
This simple yet effective automation helps maintain consistent pricing discipline and prevents unauthorized discounts — a great example of how SuiteScript adds control and intelligence to NetSuite workflows.
**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/record', 'N/ui/message'], (record, message) => {
function beforeSubmit(context) {
const newRec = context.newRecord;
const lineCount = newRec.getLineCount({ sublistId: 'item' });
for (let i = 0; i < lineCount; i++) {
const rate = parseFloat(newRec.getSublistValue({ sublistId: 'item', fieldId: 'rate', line: i })) || 0;
const amount = parseFloat(newRec.getSublistValue({ sublistId: 'item', fieldId: 'amount', line: i })) || 0;
const discount = ((rate - amount / rate) * 100);
if (discount > 20) throw 'Discount exceeds 20% limit. Please review.';
}
}
return { beforeSubmit };
});