Script to add 3% of total as credit card charge in sales order

We have decide to make use of the markup item to add a 3% of the charge to the total amount before proceeding to payment. A markup item will create on the NetSuite account we will assign the rate of markup item as 3 % of the total of the sales order. After we will add that mark up item to the item line of the sales order.

The script s added below:

/* **********************************************************************************************
* UserEventScript for adding credit card charge
* **************************************************************************
* MEGA-515: Script to add 3% of total as credit card charge in salesorder
* **********************************************************************************************
*
* Author: Jobin and Jismi IT Services
*
* Date Created : 19-october-2023
*
* Description : This script is to add 3% of total as credit ard charge in salesorder
*
* REVISION HISTORY
*
* @version 1.0 : 19-OCTOBER-2023 : Created the initial build by JJ0166
*
*
***********************************************************************************************
**/
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/

define(['N/record'], function (record) {
function beforeSubmit(context) {
try {
if (context.type !== context.UserEventType.CREATE) return false;
var salesRecord = context.newRecord;
log.debug(salesRecord);
var creditCardItem = 0;
var total = salesRecord.getValue({
fieldId: 'total'
});
total = (total || 0) * 0.03; //calculate 3% of the total
log.debug("totalafter", total);
var count = salesRecord.getLineCount({
sublistId: 'item'
})
for (var i = 1; i <= count; i++) {
var itemInList = salesRecord.getSublistValue({
sublistId: 'item',
fieldId: 'item',
line: i
})
if (itemInList === 445) {
creditCardItem++;
}
}
log.debug("creditCardItem", creditCardItem);
var creditPay = salesRecord.getValue({
fieldId: 'custbody7' // Replace 'your_field_id' with the actual field ID to check its value
});
log.debug("creditPay", creditPay);
if (creditCardItem !== 0 && creditPay === 'T') {
salesRecord.insertLine({
sublistId: 'item',
line: count
});
salesRecord.setSublistValue({
sublistId: 'item',
fieldId: 'item',
line: count,
value: 445
});
salesRecord.setSublistValue({
sublistId: 'item',
fieldId: 'price',
line: count,
value: -1
});
salesRecord.setSublistValue({
sublistId: 'item',
fieldId: 'amount',
line: count,
value: total
});
}
} catch (error) {
log.debug("error @ beforesubmit", error);
}
}
return {
beforeSubmit: beforeSubmit
};
});

Leave a comment

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