How to retrigger flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 05:45 AM - edited ‎07-20-2023 05:46 AM
we have created one flow designer , as per user requirement when approver cancels the request in step7 again flow has to restart from Step 1 ? Can someone please help me how can i achieve this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 07:25 AM
Hello @Rajeev ponuguma
Description
It is often common to have flow designer execution with errors. Additionally, when there are other integrations involved such as the Mid Server, there is a requirement to run the flow again once the root cause of the issue is corrected.
After fixing the error, many users would like to run the flow designer again.
Cause
Out of the Box, there's no "rerun" feature in Flow Designer.
Resolution
There is an option to delete the currently executing/failed out flow context and then do an update on the parent record which will re-trigger the flow
Execute the startFlow() API as our documentation page FlowAPI - Scoped, Global states.
Our developer website has some examples about it
There are some examples, in ServiceNow Developer website
Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2023 02:29 PM
restartFlowContext();
function restartFlowContext() {
// This variable tracks how many workflow contexts have been cancelled.
var cancelContext = 0;
// Get the sys_id of the current flow context record[sys_flow_context]
var currentContextID = current.flow_context.getValue('sys_id');
// Get the GlideRecord for the current flow context record[sys_flow_context]
var currentContext = new GlideRecordUtil().getGR('sys_flow_context', currentContextID);
// Check to see if the current flow context is already complete
var isCurrentContextComplete = currentContext.state.getDisplayValue();
// If the current workflow context is not already complete, cancel it before starting a new one
// Note : Flow contexts do not cancel existing tasks when they are cancelled
if (isCurrentContextComplete != "Error" && isCurrentContextComplete != "Complete" && isCurrentContextComplete != "Cancelled") {
cancelContext = sn_fd.FlowAPI.cancel(currentContextID, 'This flow is being cancelled because it is being restarted via UI action on ' + current.number.toString());
}
// Get the latest version of the workflow being used in the current workflow context
var newWorkflow = current.cat_item.flow_designer_flow.sys_scope.scope + "." + current.cat_item.flow_designer_flow.internal_name;
// Generate a new flow context
var inputs = {};
inputs['request_item'] = new GlideRecordUtil().getGR("sc_req_item", current.sys_id.toString());
inputs['table_name'] = current.getTableName();
var newWorkflowContext = sn_fd.Flow.startAsync(newWorkflow, inputs);
var contextId = newWorkflowContext != null ? newWorkflowContext.contextId : null;
// Associate the new workflow context to the current record
if (contextId) {
current.flow_context = contextId;
// Post a work note stating that the workflow context has been restarted
current.work_notes = gs.getUser().getFullName() + ' has restarted the flow context for this record';
// Update the record
current.update();
}
}
This is the code for a UI Action I created to restart a flow context in flow designer. It technically cancels the existing context and starts up a new one and re-associates it with the RITM.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2024 12:17 PM
Ken,
Amazing script code! Thanks for the snipt.
[]'s
Andre