【问题标题】:Creating a Sales Order with an Item using Netsuite SuiteScript使用 Netsuite SuiteScript 创建包含项目的销售订单
【发布时间】:2017-09-06 18:44:49
【问题描述】:

我正在尝试使用 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 中的帮助部分,但找不到为销售订单创建项目的任何内容。

感谢您提供任何答案或可以查看的地方:)

【问题讨论】:

    标签: javascript netsuite suitescript


    【解决方案1】:

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

    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

    【讨论】:

      【解决方案2】:

      这取决于您如何获取您的项目详细信息,如果您有系统中现有项目的项目 ID,那么您可以使用 API 设置它

      • 'selectNewLineItem'、'setCurrentLineItemValue'、'commitLineItem'。

      如果您只获得系统中不存在的项目名称及其字段详细信息,那么您必须使用创建一个新项目,

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

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

      谢谢

      【讨论】:

      • 谢谢!所以我需要先创建一个记录或者创建一个 SaleOrderItem 然后在保存销售订单之前添加到销售订单中?
      • 是的,没错,你必须这样做,以防你在系统中没有已经创建的项目。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      相关资源
      最近更新 更多