Reset approvals in workflow on field change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2022 02:36 AM
Hi,
I'm trying to restart the approvals of a workflow with advanced business rule. The script:
(function executeRule(current, previous /*null when async*/){
var chng = new GlideRecord('chnage_request');
chng.addQuery('number', current.number);
chng.query();
if(chng.next()){
var workflow = new global.Workflow();
workflow.cancel(chng);
new WorkflowApprovalUtils().cancelAll(chng);
workflow.restartWorkflow(chng);
}
})(current, previous);
I also tried to user the reset function of WorkflowApprovalUtils but it did not work.
Anyone have any ideas? Thanks! 🙂
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2022 05:49 AM
Your typo in the table name of the GR line is making that query not return any records.
var chng = new GlideRecord('change_request');
You shouldn't need to GR to return the current record if this BR is running on the change_request table, so maybe just try using 'current' in your workflow lines instead of 'chng'.
Once you have the correct change record, I'm not sure that you have to do the cancel steps - restarting a a workflow inherently cancels the currently running context. One line you might need after the restart is an update to 'nudge' the workflow so that it actually executes the first activity
workflow.runFlows(chng, "update");