admin管理员组

文章数量:1323348

I am attempting to write a Restlet, using SuiteScript 2.0, for my pany to create a new Sales Order. I found how to create a record.Type.Sales_Order and put in the minimums for now, but I have no idea on how to create an item for the Sales Order and include it in the SO so I can create the Sales Order.

Here is what I have so far (in a 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();

Do I create a new record of an item type and then add it to the sales order before saving? I have looked though the help section in netsuite but can't find anything with creating items for a sales order.

Thanks for any answers or places to look :)

I am attempting to write a Restlet, using SuiteScript 2.0, for my pany to create a new Sales Order. I found how to create a record.Type.Sales_Order and put in the minimums for now, but I have no idea on how to create an item for the Sales Order and include it in the SO so I can create the Sales Order.

Here is what I have so far (in a 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();

Do I create a new record of an item type and then add it to the sales order before saving? I have looked though the help section in netsuite. but can't find anything with creating items for a sales order.

Thanks for any answers or places to look :)

Share Improve this question asked Sep 6, 2017 at 18:44 Wally KolczWally Kolcz 1,6643 gold badges25 silver badges47 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

The item record must exist before adding it to the sales order. So if you need to add an item which has not yet been created, you need to create the item record first. However, if you're asking how to add an existing item to the item sublist of the sales order, you can do this:

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.mitLine({  //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

It depends on how you get your Item details, in case you have items id of an existing one in system, then you can set it using API's

  • 'selectNewLineItem', 'setCurrentLineItemValue', 'mitLineItem'.

In case you are getting only the Item name, and its fields details, which does not exist in system, then you have to create a new item using,

1) var xyz = createRecord('item') 2) use xyz will have an id of created Item, use it to set it in the Sales order.

Note: API's are not exact names, they are just representing their usage.

Thanks

本文标签: javascriptCreating a Sales Order with an Item using Netsuite SuiteScriptStack Overflow