Reputation: 217
Is there a way to display the shipping costs in creating a sales order like what the NetSuite web form has? As far as I know, there's a setting per shipping item if it is set to a flat rate, a shipping table, and other rules to be considered like maximum rates, etc.
So, should I do a manual computation instead? Or something else?
Upvotes: 1
Views: 901
Reputation: 217
If you're using SuiteScript, use the nlapiCreateRecord method shown below:
var record = nlapiCreateRecord('salesorder', {'recordmode': 'dynamic'});
Setting recordmode to dynamic is important otherwise the computations will always be 0.
Next, set the shipping method with its internal ID.
record.setFieldValue('shipmethod', input.shipping_method);
Next, loop through the list of items from your json data, then commit line item before going to the next iteration:
// sample json data on one item (all attributes are internal IDs except quantity)
[
{"id":6657,"quantity":2,"units":16,"price":1,"taxcode":22},
{"id":3941,"quantity":1,"units":16,"price":1,"taxcode":22}
]
// start
record.selectNewLineItem('item');
record.setCurrentLineItemValue('quantity', item.quantity);
// duplicate setCurrentLineItemValue and change the parameters to
// units, price, taxcode respectively
record.commitLineItem('item');
// end
Lastly, you can get the shipping cost by using getFieldValue method:
record.getFieldValue('shippingcost');
Note that you can also get the values for subtotal, taxtotal, and total (or overall total cost).
Upvotes: 1