Workflow Issue: A workflow is struck in an activity and doesnot advance to its next activity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2018 05:49 AM
I have a workflow that contains activities such as catalog tasks and switches.
My workflow has been working good for many months but recently I saw a workflow context that stopped at the catalog task, and doesn't advance to the next activity (a switch) upon the task closure.
I see a log entry in that context that says "After running a sequence of activities we expected a 'last executing' record to predict the future stages from".
I tried Nudge option but got the same log entry again in the content. Only one workflow context has this issue, others are just fine.
Can someone help me on this logged error?
- Labels:
-
Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2018 06:19 AM
Hi - May i know which type of workflow activity got stuck ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2018 07:42 AM
Catalog Task is the activity where the workflow stopped. Its next activity is a switch.
It is a one-time issue, which I am trying to debug based on that log entry. It is not a recurring issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2018 07:32 AM
In case this is still oustanding -- what probably happened is that the field/variable that the switch statement runs against was completely blank.
The only way to fix the workflow is to manually delete the latest workflow activity history record, insert a proper workflow executing activity record, and then re-nudge the workflow.
This same error can occur on any Workflow activity that has conditions on it's transitions, and due to a missing required field or something, none of the transitions match.
Script below may help you -- just pass in a GlideRecord (such as "current")
---------------------------------------------------------------------------
function rerunWorkflowActivity(record) {
//Grab the workflow context
var context = new GlideRecord("wf_context");
context.addQuery("table", record.getTableName());
context.addQuery("id", record.sys_id.toString());
context.addQuery("state", "executing");
context.setLimit(1);
context.query();
if(!context.next()) {
gs.print("ERROR: Could not find workflow context.");
return false;
}
//Check if there's a current executing activity. If so, just poke/nudge the workflow.
var executing = new GlideRecord("wf_executing");
executing.addQuery("context", context.sys_id.toString());
executing.setLimit(1);
executing.query();
if(executing.next()) {
gs.print("SUCCESS: Found a currently executing workflow activity. Nudging the workflow.");
new Workflow().broadcastEvent(context.sys_id.toString(), 'update');
return true;
}
//Grab the most recent workflow activity history
var history = new GlideRecord("wf_history");
history.addQuery("context", context.sys_id.toString());
history.orderByDesc("activity_index");
history.setLimit(1);
history.query();
if(!history.next()) {
gs.print("ERROR: Could not find last workflow activity.");
return false;
}
//Grab the most recent workflow transition
var transition = new GlideRecord("wf_transition_history");
transition.addQuery("context", context.sys_id.toString());
transition.addQuery("transition.to", history.activity.toString());
transition.setLimit(1);
transition.query();
if(!transition.next()) {
gs.print("ERROR: Could not find latest workflow transition.");
return false;
}
if(transition.transition.from.toString() === "") {
gs.print("ERROR: Latest workflow transition had a blank 'from' value.");
return false;
}
//Grab previous activity
var previous = new GlideRecord("wf_history");
previous.addQuery("context", context.sys_id.toString());
previous.addQuery("activity", transition.transition.from.toString());
previous.setLimit(1);
previous.query();
if(!previous.next()) {
gs.print("ERROR: Could not find the previous workflow activity in the workflow history.");
gs.print(previous.getEncodedQuery());
return false;
}
//Prep the context
context.activity_count = executing.activity_index.toString();
context.activity_index = executing.activity_index.toString();
executing = new GlideRecord("wf_executing");
executing.newRecord();
executing.activity = history.activity.toString();
executing.activity_index = history.activity_index.toString();
executing.context = context.sys_id.toString();
executing.input_data = history.input_data.toString();
executing.is_parent = history.is_parent.toString();
//executing.notify_termination = false;
executing.output_data = history.output_data.toString();
executing.parent = history.parent.toString();
executing.previous_activity = previous.sys_id.toString();
executing.started = history.started.toString();
executing.state = "executing";
executing.sys_domain = history.sys_domain.toString();
executing.sys_domain_path = history.sys_domain_path.toString();
executing.workflow_version = history.workflow_version.toString();
//Delete the history record.
history.deleteRecord();
//Insert the new executing record
executing.insert();
//Update the context
context.update();
//Poke the workflow.
new Workflow().broadcastEvent(context.sys_id.toString(), 'update');
gs.print("SUCCESS: Deleted the latest activity in the history, inserted it again as an executing activity, and poked the workflow.");
return true;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2019 08:44 AM
Hi @garrettgriffin , I have just stumbled across this as having a similar issue.
When you say "just pass in a GlideRecord (such as "current")", can you elaborate on this for me as relatively new to this world!
Would I run as a background script? I have the sys ID of context thats hasn't moved on, how would I script this into your script to delete and re-create the history?
Many thanks for any help you can provide