Since the shipping costs and handling charges are 2 separate fields in the sales orders, to know the total shipping charges we always need to get our calculators and add them together.
To avoid this we created a custom body field called "custbodytotship" which is updated with the sum of the shipping/handling charges. We got this to work every time an order is entered manually and saved, but not when the orders come from the web. We need to manually edit and save the order for this field to be updated.
We want to to have this custom field updated every time we APPROVE an order. So we created the following script:
function calculateShippingOnApprove(type)
{
var hand = nlapiGetFieldValue('handlingcost');
var ship = nlapiGetFieldValue('shippingcost');
var newship = Math.round(((hand*1)+(ship*1))*100)/100 ;
nlapiSetFieldValue('custbodytotship',newship);
}
Then in NS we created an script through Setup > Customization > Script where in the Before Submit Function it calls the calculateShippingOnApprove function.
In the Deployments tab we selected:
Applies to: Sales Order
Deployed: Yes
Status: Released
Event: Approve
But when we Approve the sales orders the custom field is not being updated. What are we doing wrong? Any help is appreciated.