Restart/Retrigger a flow designer
Hi Community,
In recent times I had a requirement to restart/retrigger a flow designer, the use case was to cancel the existing flow when the date field gets modified(there was a wait for condition on that date field). So when the date gets updated by fulfiller the existing flow should get cancelled and the new flow show start with the updated date. This use case was used in employee termination process.
So I have achieved this by a business rule.
When to run: After update on the catalog item.
Advanced condition: current.variables.'variable_name'.changes()
Note: Please update the variable_name to the variable name.
------------------------------------------------------------------------------------------------------------------
Script:
(function executeRule(current, previous /*null when async*/ ) {
var now_GR = new GlideRecord("sys_flow_context"); now_GR.addQuery("name", "xxxxxx");// flow designer name now_GR.addQuery("source_record="+current.sys_id);
now_GR.query();
while (now_GR.next()) { sn_fd.FlowAPI.cancel(now_GR.getUniqueValue(), 'Canceling xxxxxxx'); // flow designer name
}
startFlowDesignerFlow(current);
function startFlowDesignerFlow(current) { var flow = current.cat_item.flow_designer_flow;
var flowName = flow.sys_scope.scope + "." + flow.internal_name;
sn_flow_trigger.FlowTriggerAPI.fireCatalogTrigger(flowName, current);
}
})(current, previous);
------------------------------------------------------------------------------------------------------------------
This restart/retrigger flow designer can also be used in different scenario's.
https://www.servicenow.com/community/itsm-articles/restart-retrigger-a-flow-designer/ta-p/2306116
