从销售订单到项目履行错误的转换

Transformation from Sales Order to Item Fulfillment Error

我在将销售订单转换为项目履行时遇到了一些问题。这是我的代码:

/**
 * @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
};

});

我一直收到这个错误,这有点令人困惑,因为我不知道 "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}

我看到您在 header 中设置了位置字段,但根据错误,您还需要在项目子列表中设置位置字段。

当 Netsuite 无法获取您在脚本中分配的值时会出现此错误。位置是 List/Record 类型。您正在根据价值设置位置。尝试使用 setText 而不是 setValue。

查看记录浏览器,我在 Fulfillment 上看不到任何位置字段 header https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2020_1/script/record/itemfulfillment.html 这应该有效:-

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