Why is my workflow action script taking so long to run?
I found a script that was being used to change a Sales Order status and decided to try and use it for a return authorization approval workflow. The script does successfully change the status from Pending Approval to Pending Receipt after at least a minute of “thinking”. When I check the execution log it shows the funcName “Starting” happening 15 times before returning the “approved”. I am using saved searches to transition the ones I want cancelled to other states and if the RMA is not caught on any of those it moves to the approved state where this script happens. Any pointers?
/**
* @NApiVersion 2.x
* @NScriptType workflowactionscript
*/
define([‘N/record’],
function(record) {
var scriptName = “RTN_Approved “;
“use strict”;
function onAction(context) {
var funcName = scriptName + “onAction ” + context.newRecord.type + ” ” + context.newRecord.id;
log.debug(funcName, “Starting”);
try {
var RTN = record.load({type: context.newRecord.type, id: context.newRecord.id});
RTN.setValue({
fieldId: ‘orderstatus’,
value: ‘B’});
RTN.save();
log.debug(funcName, “approved”);
} catch (e) {
log.error(funcName + “Unable to approve error”, e)
}
}
return {
onAction : onAction
};
});
Test this script without workflow, if taking same time then go in detail of script.
I figured it out. My transaction was leaving and entering the workflow by the time it was making the changes so once I made it so the transaction did not exit the script did exactly what I wanted.