Preethi
09/30/2025, 12:40 AM/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/record', 'N/log'], function(record, log) {
function beforeSubmit(context) {
try {
if (context.type === context.UserEventType.CREATE ||
context.type === context.UserEventType.EDIT) {
var newRecord = context.newRecord;
var lineCount = newRecord.getLineCount({ sublistId: 'inventory' });
log.audit('Script Started', 'Line Count: ' + lineCount);
for (var i = 0; i < lineCount; i++) {
var customCost = newRecord.getSublistValue({
sublistId: 'inventory',
fieldId: 'custcol_avg_cost',
line: i
});
log.audit('Line ' + i, 'Custom Cost: ' + customCost);
if (customCost && customCost !== null && customCost !== '') {
newRecord.setSublistValue({
sublistId: 'inventory',
fieldId: 'unitcost',
line: i,
value: parseFloat(customCost)
});
log.audit('Line ' + i, 'Unit Cost Set to: ' + customCost);
}
}
}
} catch (e) {
log.error('Error in beforeSubmit', e.message + ' | ' + e.stack);
}
}
return {
beforeSubmit: beforeSubmit
};
});
Anthony OConnor
09/30/2025, 12:52 AMPreethi
09/30/2025, 1:29 AMPreethi
09/30/2025, 1:55 AMAnthony OConnor
09/30/2025, 2:14 AMAnthony OConnor
09/30/2025, 2:15 AMAnthony OConnor
09/30/2025, 2:15 AM