Is there a way to restart a workflow if it is accidentally closed?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2018 08:44 AM
I wanted to find out if there is a way that a workflow can be restarted if the request item is closed by accident for whatever reason. This seems to be happening more and more often and we always get the same question "Can the request be reopened?"
I want to be very specific in my question, so let's say the Workflow Started and it contains the following normal activities:
a. Workflow Begins
b. RITM is set to Requested / Work in Progress
c. Waits for the Manager Approval, once approved
d. Sets the RITM to Approved / Work in Progress
e. Goes thru the process of creating the tasks, etc.
f. After all tasks are closed then the workflow ends and RITM is closed.
Use Case ~ let's say the workflow gets all the way to creating Task # 1, but the task was closed by accident. I want to know Is there a way to restart the wf and have it either start over or start from where the task was re-opened? If this is possible, you also provide the benefits of doing this / or the risks involved (if any).
Thanks,
Karen

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2018 08:56 AM
Yes, you can restart workflow by running below code
new Workflow().restartWorkflow(current);
https://docs.servicenow.com/bundle/london-application-development/page/app-store/dev_portal/API_reference/Workflow/concept/c_Workflow_api.html#ariaid-title17
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2018 09:00 AM
There is no OOB UI action to restart a workflow but it would be possible to script a UI action tied to the RITM that would allow the restart via the workflow method workflow().restartWorkflow(). This risks are legion considering you may have tasks that have been actually completed and a new workflow would need to resolve these discrepancies. The simpliest/cleanest method would be to cancel the RITM and resubmit the request. This could either be done manually or automatically scripted by a UI action which creates a cart, adds the RITM and does a submit on the cart. Lots of code examples of these so I won't take the time to repeat them.
If this reply is helpful or answers your question please mark it so. I'm trying to catch up to Chuck Tomasi sometime in this life span.