JR
09/03/2025, 3:07 PM/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(['N/record', 'N/ui/dialog', 'N/log', 'N/error'], function(record, dialog, log, error) {
function validateLine(scriptContext) {
var currentRecord = scriptContext.currentRecord;
var sublistId = scriptContext.sublistId;
var myItem = currentRecord.getCurrentSublistValue({
sublistId: sublistId,
fieldId: 'item'
});
if (myItem === '42343') {
// If validation passes and a new line should be added
try {
// Select a new line in the same sublist
currentRecord.selectNewLine({
sublistId: sublistId,
});
// Set values for the new line
currentRecord.setCurrentSublistValue({
sublistId: sublistId,
fieldId: 'item',
value: 52154
});
// ... set other field values as needed
currentRecord.setCurrentSublistValue({
sublistId: sublistId,
fieldId: 'location',
value: 14
});
currentRecord.setCurrentSublistValue({
sublistId: sublistId,
fieldId: 'quantity',
value: 2
});
// Commit the new line
currentRecord.commitLine({
sublistId: sublistId,
});
} catch (e) {
// Handle any errors during line creation
log.error({
title: 'Error adding new line',
details: e.message
});
}
}
// Always return true to allow the original line to be committed
return true;
}
return {
validateLine: validateLine
};
});
Anthony OConnor
09/03/2025, 3:18 PMJR
09/03/2025, 5:17 PMAnthony OConnor
09/03/2025, 5:28 PMJR
09/03/2025, 5:34 PMJR
09/03/2025, 5:36 PMAnthony OConnor
09/03/2025, 5:39 PMAnthony OConnor
09/03/2025, 5:39 PMAnthony OConnor
09/03/2025, 5:40 PMAnthony OConnor
09/03/2025, 5:41 PMAnthony OConnor
09/03/2025, 5:42 PMAnthony OConnor
09/03/2025, 5:43 PMAnthony OConnor
09/03/2025, 5:43 PMJR
09/03/2025, 5:56 PM