2

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}
Avi
  • 2,014
  • 1
  • 9
  • 21
CodeMonkey
  • 97
  • 2
  • 9

3 Answers3

2

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.

Rusty Shackles
  • 2,802
  • 10
  • 11
0

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.

SahooCodex
  • 48
  • 10
0

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();
}