Hello, We have Group Average Costing enabled. We h...
# suitescript
p
Hello, We have Group Average Costing enabled. We have also created a custom field to source the Average Cost. This field has been made available on Inventory Adjustment (IA) at the line level. The expectation is to copy the value from this custom field to Est. Unit Cost (native field). Since the native field is not available on workflows, we created a user event script to copy the value. But when saving the IA, we get the 500 error, which I found out by checking the browser console. Attaching the code here if someone can help where the issue is.
/**
* @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
};
});
a
what if anything are you logs showing? you have various logs in here.... not sure why a 500 error would be a suitescript error tbh
p
@Anthony OConnor that's what surprises me, I'm not seeing anything in logs
I'm new to SuiteScripting. I created user event script since I could not find the native field, Est. Unit Cost in the Inventory Transaction workflow.
a
ok is your script deployed and released?
you have a log at the start just saying script started, if its not logging that then nothing after that matters
you're not getting to that point so something else is wrong