Reputation: 117
I'm having some trouble transforming a sales order to item fulfillment. Here is my code:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/record', 'N/log'],
function(record, log) {
function afterSubmit(context) {
var orderId = context.newRecord.id;
var fulfillmentRecord = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: orderId,
toType: record.Type.ITEM_FULFILLMENT,
isDynamic: true
});
fulfillmentRecord.setValue({
fieldId: 'location',
value: 'San Francisco'
});
log.error({
title: 'Debug Entry',
details: fulfillmentRecord
});
var rid = fulfillmentRecord.save();
}
return {
afterSubmit: afterSubmit
};
});
I keep getting this error, which is a little confusing because I don't know what they mean by "stack":
{"type":"error.SuiteScriptError",
"name":"USER_ERROR",
"message":"Please provide values for the following fields in the Items list: Location",
"stack":["anonymous(N/serverRecordService)",
"afterSubmit(/SuiteScripts/fulfillmentCreator.js:23)"],
"cause":{
"type":"internal error",
"code":"USER_ERROR",
"details":"Please provide values for the following fields in the Items list: Location",
"userEvent":"aftersubmit",
"stackTrace":["anonymous(N/serverRecordService)","afterSubmit(/SuiteScripts/fulfillmentCreator.js:23)"],"notifyOff":false},"id":"","notifyOff":false}
Upvotes: 2
Views: 2703
Reputation: 53
Looking at the record browser, I cannot see any location field on Fulfillment header https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2020_1/script/record/itemfulfillment.html This should work:-
function afterSubmit(context) {
var orderId = context.newRecord.id;
var fulfillmentRecord = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: orderId,
toType: record.Type.ITEM_FULFILLMENT,
isDynamic: true
});
var lineCount = fulfillmentRecord.getLineCount({sublistId:'item});
for(var i=0;i<lineCount; i++){
fulfillmentRecord.selectLine({sublistId:'item',line:i});
fulfillmentRecord.setCurrentSublistValue({
sublistId:'item',
fieldId: 'location',
value: '123' //Enter the location internal id, instead of name i.e San Francisco
});
}
log.error({
title: 'Debug Entry',
details: fulfillmentRecord
});
var rid = fulfillmentRecord.save();
}
Upvotes: 0
Reputation: 48
This error comes when Netsuite can't fetch value that you are assigning in the script. Location is List/Record type. And you are setting location based on value. Try to use setText instead of setValue.
Upvotes: 0
Reputation: 2850
I see that you have set the location field at the header but based on the error, you will also need to set the location field on the item sublist.
Upvotes: 2