Reputation: 11
First, I'm very new to scripting in NetSuite, so please forgive the scrappy code.
I'm trying to create a script (yes, I know this can be done in a workflow) that loops back through the lines of a sales order and copies the line 'amount' over to the 'altsalesamt' field after the order is saved. The script runs okay but doesn't actually do anything.
function afterSubmit_setASA(){
var soItemCount = nlapiGetLineItemCount('item');
for (var i = 1; i <= soItemCount; ++i) {
var lineamt = nlapiGetLineItemValue('item', 'amount', i);
if (lineamt != null && lineamt != '') {
nlapiSetLineItemValue('item', 'altsalesamt', i, lineamt);
}
}
}
Can anyone point me in the right direction of what I may need to change or do? Any help is greatly appreciated!!
Upvotes: 1
Views: 3789
Reputation: 577
You forgot to submit: nlapiSubmitRecord(...);
You can also try this code:
var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());
var soItemCount = record.getLineItemCount('item');
for (var i = 1; i <= soItemCount; ++i) {
var lineamt = record.getLineItemValue('item', 'amount', i);
if (lineamt != null && lineamt != '') {
record.setLineItemValue('item', 'altsalesamt', i, lineamt);
}
}
var id = nlapiSubmitRecord(record, true);
Upvotes: 0
Reputation: 8847
You are doing this in the After Submit event. At this point, the record has already been submitted to the database. You have two options:
I would recommend option 2, as this will use less governance, be more performant, and result in less database queries.
Upvotes: 2