Sets payment profile in sales order.

Jira Code: PROT-149

This workflow action script triggers when a sales order is created. It will check the department of the customer and set the payment profile based on the department.

define(['N/record'],
function(record) {   
    function onAction(scriptContext) {
    	try {
    		var soRecord = scriptContext.newRecord;    		
    			var dept = soRecord.getValue({
        			fieldId: 'department'
        		});
        		logme('dept',dept);
        		if(dept == 1){
        			logme('Protec Dep');
        			soRecord.setValue({
        				fieldId: 'creditcardprocessor',
        				value: 2
        			});
        		}else if(dept == 2){
        			logme('Boulevard Dept');
        			soRecord.setValue({
        				fieldId: 'creditcardprocessor',
        				value: 3
        			});
        		}else{
        			logme('Dont set payment profile');
        		}
		} catch (e) {
			logme('err@onAction',getError(e));
		}
    }

    return {
        onAction : onAction
    };
    
});
/*******************************************************************
 * Log these data 
 * @param title
 * @param details
 * @returns 
 * Created on 09-Aug-2017 by rosemol
 */
function logme(title, details) {
	log.debug({
		title : title,
		details : details
	});
}
/*******************************************************************
 * return error
 * 
 * @param e
 * @returns {String}
 */
function getError(e) {
	var stErrMsg = '';
	if (e.getDetails != undefined) {
		stErrMsg = '_' + e.getCode() + '<br>' + e.getDetails()
		+ '<br>' + e.getStackTrace();
	} else {
		stErrMsg = '_' + e.toString();
	}
	return stErrMsg;
}

Leave a comment

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