Jira Code: HTL-28
If Customer TERMS = CASH and an Item starting with “8” are being ordered, make the status of SO to “Appending Approval” and make “Hold for Payment” Ticked (True).
If Customer TERMS = CASH and no Items starting with “8” are being ordered, make “Hold for Payment” Ticked (True).
If “Hold for Payment” is being changed to unticked (False), make status “Pending fulfilment”.
User Event Script: HTL-28 JJ UE SO Status
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/**
* Script Description: This script is for setting Status on SO based on Hold for Payment
*/
/*******************************************************************************
* * AN * *
* **************************************************************************
* Date:06/11/18
* Script name: HTL UE SO Status Change
* Script id: customscript_htl_25_ue_status_change
* Deployment id: customdeploy_htl_25_ue_status_change
* Applied to: Sales Order
*
******************************************************************************/
define(['N/record'],
function(record) {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type
* @Since 2015.2
*/
function beforeSubmit(scriptContext) {
try {
var hold_payment = scriptContext.newRecord.getValue({
fieldId : 'custbody3'
});
var status = scriptContext.newRecord.getValue({
fieldId : 'orderstatus'
});
var status_txt = scriptContext.newRecord.getText({
fieldId : 'orderstatus'
});
if(hold_payment==false){
scriptContext.newRecord.setValue({
fieldId : 'orderstatus',
value :'B',
});
}else{
scriptContext.newRecord.setValue({
fieldId : 'orderstatus',
value :'A',
});
}
} catch (e) {
log.error(e.name,e.message);
}
}
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type
* @Since 2015.2
*/
function afterSubmit(scriptContext) {
}
return {
//beforeLoad: beforeLoad,
beforeSubmit: beforeSubmit
//afterSubmit: afterSubmit
};
});