User Event Script for updating Shipping Cost from transaction body field value when a user place order from the Website.

When user place order from the Website In Netsuite we change the shipping cost that is in transaction body field by using this User Event Script.

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(['N/record'],
	function (record) {
		function beforeSubmit(context) {
			//function is used to add the shipping cost to sales order
			try {
				var currentRecord = context.newRecord;
				var shippingString = currentRecord.getValue({
					fieldId: 'custbody_custom_shipping_cost'
				});
              log.error('shippingString', shippingString);
				if (shippingString) {
                  var shippingObject = JSON.parse(shippingString);
                  log.error('shippingObject', shippingObject);
					currentRecord.setValue({
						fieldId: 'shippingcost',
						value: parseFloat(shippingObject.shipRate)
					});
				}
			} catch (error) {
				log.debug('Error @ Invoice No', error);
			}
			return true;
		}
		return {
			beforeSubmit: beforeSubmit
		};
	}
);

Leave a comment

Your email address will not be published. Required fields are marked *