使用 Netsuite SuiteScript 创建包含项目的销售订单

Creating a Sales Order with an Item using Netsuite SuiteScript

我正在尝试使用 SuiteScript 2.0 为我的公司编写一个 Restlet 来创建一个新的销售订单。我找到了如何创建 record.Type.Sales_Order 并暂时放入最小值,但我不知道如何为销售订单创建项目并将其包含在 SO 中以便我可以创建销售订单。

这是我目前所拥有的(在 GET 中):

   var salesOrder = record.create({
                type: record.Type.SALES_ORDER, 
                isDynamic: true,
                defaultValues: {
                    entity: param.customer_id
                } 
            });

salesOrder.setValue('trandate', new Date()),
salesOrder.setText('orderstatus','Pending Fulfillment'); 
salesOrder.setValue('memo','Sales Order Generated from ' + param.customer_name);
salesOrder.save();

我是否创建一个项目类型的新记录,然后在保存之前将其添加到销售订单中?我查看了 netsuite.com 中的帮助部分,但找不到有关为销售订单创建项目的任何内容。

感谢您提供任何答案或寻找的地方:)

这取决于您如何获取商品详情,如果您有系统中现有商品的商品 ID,则可以使用 API 的

进行设置
  • 'selectNewLineItem', 'setCurrentLineItemValue', 'commitLineItem'.

如果您只获得系统中不存在的项目名称及其字段详细信息,则必须使用

创建一个新项目

1) var xyz = createRecord('item') 2) 使用 xyz 将有一个创建的项目的 id,用它来设置它在销售订单中。

注意:API 不是确切的名称,它们只是代表它们的用法。

谢谢

项目记录必须存在才能添加到销售订单。所以如果你需要添加一个还没有被创建的项目,你需要先创建项目记录。但是,如果您询问如何将现有商品添加到销售订单的商品子列表中,您可以这样做:

var salesOrder = record.create({
            type: record.Type.SALES_ORDER, 
            isDynamic: true,
            defaultValues: {
                entity: param.customer_id
            } 
        });

salesOrder.selectNewLine({ //add a line to a sublist
    sublistId: 'item'      //specify which sublist
});

salesOrder.setCurrentSublistValue({   //set item field
    sublistId: 'item',
    fieldId: 'item',
    value: {{itemid}}  //replace with item internal id 
});
salesOrder.setCurrentSublistValue({
    sublistId: 'item',
    fieldId: 'quantity',
    value: {{quantity}} //replace with quantity
});

//repeat above pattern to set the rest of the line fields

salesOrder.commitLine({  //writes the line entry into the loaded record
    sublistId: 'item'
});

salesOrder.save({                  //writes record back to database
    ignoreMandatoryFields: true    //set for testing in case you want to create a record without validating which can give errors
});

HTH