oLraX oLraX - 1 month ago 15x
Javascript Question

Suitescript - Fetch and display shipping cost on sales order form

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?


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)

// start
    record.setCurrentLineItemValue('quantity', item.quantity);
    // duplicate setCurrentLineItemValue and change the parameters to 
    // units, price, taxcode respectively
// end

Lastly, you can get the shipping cost by using getFieldValue method:


Note that you can also get the values for subtotal, taxtotal, and total (or overall total cost).