使用 Dropship 默认值创建采购订单时缺少项目

问题描述 投票:0回答:3

我正在尝试通过 SuiteScript 2 创建 Dropship 采购订单。我能够使用正确的 Dropship 数据(客户、销售订单、Dropship 表单)创建采购订单对象,但是在保存时出现以下错误

“您必须为此交易至少输入一个行项目。”。

我可以从销售订单手动创建直运,并且项目添加得很好。我正在使用 Netsuite OneWorld。

下面是我正在使用的代码

var purchaseOrder = record.create({
                type: record.Type.PURCHASE_ORDER,
                isDynamic: true,
                defaultValues: {
                    soid: 4427821,
                    dropship: true,
                    subsidiary: 9,
                    custid: 666,
                    entity: 322
                }
});
purchaseOrder.setValue({
    fieldId: "employee",
    value: 3
});
    
log.debug("Item Count", purchaseOrder.getLineCount("item"));
log.debug("Entity", purchaseOrder.getText("entity"));
log.debug("Customer", purchaseOrder.getText("shipto"));
log.debug("Sales Order", purchaseOrder.getText("createdfrom"));
log.debug("Form", purchaseOrder.getText("customform"));
log.debug("Subsidiary", purchaseOrder.getText("subsidiary"));
    
purchaseOrder.save();

这里还有一些屏幕截图

销售订单

手动代发货 PO

脚本日志

我有创建独立 PO 的现有脚本,因此我对此处所需的流程有一些了解。对于 Dropships,我是否缺少一个具体步骤?我发现了这个帖子,其中 Will Charbonneau 说这应该是您所需要的全部Netsuite:如何将采购订单链接到销售订单。我已经用我的 ID 尝试了他们的代码,结果出现了同样的错误。

netsuite suitescript suitescript2.0
3个回答
1
投票

defaultValue 对象仅接受

entity
值。请查看
record.create defaultValue
文档

要添加您的货件项目,您可以通过将任何其他项目添加到

item
子列表来完成。

var purchaseOrderRecordObj = record.create({
    type: record.Type.PURCHASE_ORDER,
    isDynamic: true,
    defaultValues: {
        entity: 322
    }
});

purchaseOrderRecordObj.setValue({ fieldId: 'createdfrom', value: 4427821, ignoreFieldChange: false }); //createdfrom no soid
purchaseOrderRecordObj.setValue({ fieldId: 'subsidiary', value: 9, ignoreFieldChange: false });
purchaseOrderRecordObj.setValue({ fieldId: 'memo', value: "Created from Sales Order as Dropship", ignoreFieldChange: false });    
purchaseOrderRecordObj.setValue({ fieldId: 'employee', value: 3, ignoreFieldChange: false });

purchaseOrderRecordObj.selectNewLine({ sublistId: 'item' });
purchaseOrderRecordObj.setCurrentSublistValue({ sublistId: 'item', fieldId: 'item', value: '<DROP_SHIP_ITEM_ID', ignoreFieldChange: false })
//if you want to change the quantity, or the price do here ... 
purchaseOrderRecordObj.commitLine({ sublistId: 'item', ignoreRecalc: false })

purchaseOrderRecordObj.save({ ignoreMandatoryFields: true });

希望这有帮助。


0
投票

我能够重现您遇到的相同错误,下面的代码显示了解决方案。这已在脚本调试器中测试成功。

require(['N/record', 'N/log'],
function(record, log) {
    var purchaseOrder = record.create({
        type: record.Type.PURCHASE_ORDER,
        isDynamic: true,
        defaultValues: {
            soid: 1 /* random sales order */,
            dropship: true,
            subsidiary: 1 /* the one and only in my account */,
            custid: 4 /* Entity Internal ID for Customer: Powerslide */,
            entity: 10 /* Entity Internal ID for Vendor: Salesforce */
        }
    });

    purchaseOrder.setValue({
        fieldId: "employee",
        value: 3 /* me */
    });

    // -----
    // BEGIN: Add a line to the purchase order, so as to avoid the error,
    //        "You must enter at least one line item for this transaction"
    // -----
    purchaseOrder.selectNewLine({
        sublistId: 'item'
    });

    purchaseOrder.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'item',
        value: 6 /* Non-inventory Item for Purchase */
    });

    purchaseOrder.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'quantity',
        value: 1
    });

    purchaseOrder.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'rate',
        value: 10000 /* casual $10k */
    });

    purchaseOrder.commitLine({sublistId: 'item'});
    // -----
    // END: Add a line to the purchase order
    // -----

    log.debug("Item Count", purchaseOrder.getLineCount("item"));
    log.debug("Entity", purchaseOrder.getText("entity"));
    log.debug("Customer", purchaseOrder.getText("shipto"));
    log.debug("Sales Order", purchaseOrder.getText("createdfrom"));
    log.debug("Form", purchaseOrder.getText("customform"));
    log.debug("Subsidiary", purchaseOrder.getText("subsidiary"));

    purchaseOrder.save();
});

看来关键步骤如下。

  1. 使用
    Record.selectNewLine()
    开始构建新线。
  2. 使用
    Record.setCurrentSublistValue()
    填充新行上的字段。
  3. 填充完字段后,请使用
    Record.commitLine()

该解决方案的关键部分来自另一个答案。只是在应得的信用处给予信用。 🙂


0
投票

所以,如果有人仍然遇到问题,我想出了办法。

var purchaseOrder = record.create({
            type: record.Type.PURCHASE_ORDER,
            isDynamic: true,
            defaultValues: {
                customform: 180, //dropship custom form
                soid: 4820583, //Sales order internalID
                shipgroup: 1, //from 'dropship' button url via UI
                dropship: true, //from 'dropship' button url via the UI
                custid: 666, //customer InternalID
                entity: 322, //vendor InternalID
                poentity: 322 //vendor InternalID
            }
        });
var poid = purchaseOrder.save();

我不知道为什么这些字段中有一半没有记录在任何地方(默认值或架构),但这会自动填充项目和客户详细信息,就像通过 UI 一样。

© www.soinside.com 2019 - 2024. All rights reserved.