diff --git a/Specialized Areas/Fix scripts/Nudge errored workflow/Execute wf activity by sysid.js b/Specialized Areas/Fix scripts/Nudge errored workflow/Execute wf activity by sysid.js new file mode 100644 index 0000000000..24c422b114 --- /dev/null +++ b/Specialized Areas/Fix scripts/Nudge errored workflow/Execute wf activity by sysid.js @@ -0,0 +1,29 @@ +/* + * dirty fix to make workflow execute at wanted activity after error or wrong path for example + * run as fix script or in bg. + */ +var wfContextId = "ca1ba1bc83e83210557ff0d6feaad37d", + wfActivityId = "b18321f083e83210557ff0d6feaad39d"; + +(function (wfContextId, wfActivityId) { + //check valid context sysid + var contextToFix = new GlideRecord("wf_context") + if (!contextToFix.get(wfContextId)) { + return null; + } + //set context state as executing + if (contextToFix.getValue("state") != "executing") { + contextToFix.setValue('state', 'executing'); + contextToFix.update(); + } + //create instance of activity [wf_activity] to execute + var activityToContinueFromGr = new GlideRecord("wf_executing"); + activityToContinueFromGr.newRecord(); + activityToContinueFromGr.setValue("context", wfContextId); + activityToContinueFromGr.setValue("activity", wfActivityId); + activityToContinueFromGr.setValue("state", "executing"); + activityToContinueFromGr.insert(); + + //send the update event to make the executing activity run + new Workflow().broadcastEvent(wfContextId, 'update'); +})(wfContextId, wfActivityId) diff --git a/Specialized Areas/Fix scripts/Nudge errored workflow/README.md b/Specialized Areas/Fix scripts/Nudge errored workflow/README.md new file mode 100644 index 0000000000..cc5dcc538d --- /dev/null +++ b/Specialized Areas/Fix scripts/Nudge errored workflow/README.md @@ -0,0 +1,17 @@ +# Workflow recovery script + +This script provides a quick and dirty fix for resuming a stuck or misrouted workflow in ServiceNow. It manually forces a workflow context to resume execution from a specified activity, bypassing errors or incorrect transitions. + +## Purpose + +Workflows in ServiceNow can occasionally get stuck due to: +- Misconfigured transitions +- Script errors +- Unexpected data conditions + +This script allows you to manually resume execution from a desired activity within a workflow context. + +## How to + +Change the value of the variables in the script to the [wf_context] sys_id (wfContextId) and the [wf_activity] sys_id (wfActivityId) +