Reputation: 1664
I am attempting to write a Restlet, using SuiteScript 2.0, for my company 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.com but can't find anything with creating items for a sales order.
Thanks for any answers or places to look :)
Upvotes: 0
Views: 9032
Reputation: 5286
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.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
Upvotes: 7
Reputation: 31
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
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
Upvotes: 0