Workflow Wait for Condition

jfarrer
Mega Guru

I have a workflow where I want to wait for a deployment date before continuing on with the workflow. The date is supplied by the person filling out the form. I have included a "Wait for Condition" activity with a script that compares the current date to the deployment date. The script is working fine but it only checks when something is updated on the Requested Item. The workflow is not waiting for anything else besides a date to pass.

In reading this:
Wait for Condition - Attachments
and this:
http://wiki.service-now.com/index.php?title=Force_Workflow_to_Wait_on_Non-Workflow_Task
it looks like I need to have a script to "nudge" the workflow to recheck for pending activities. I was surprised to see that a "nudge" was required in the first place.

I have set up the following script to run as a Scheduled Job every 10 minutes and it seems to be working, but it does go through and trigger every workflow to recheck, which seems like a lot of overhead.



forceReqItemUpdate();

function forceReqItemUpdate() {
var wf = new Workflow();
var gr = new GlideRecord("sc_req_item");
gr.addQuery("active", true);
gr.query();
while(gr.next()) {
//gs.log("Triggering workflow for: " + gr.number);
wf.runFlows(gr, 'update');
}
}


I don't want to be doing more than is necessary. I thought about trying to trigger for just this workflow, but I would like for the "Wait for Condition" to work more generally. I also thought about trying to check for just active workflows that have a "Wait for Condition" in them, but didn't see an easy way to do this.

Any ideas for a better way?

17 REPLIES 17

Jay_Ford
Kilo Guru

Why not just use a Timer in your workflow? Set the timer using the script method by using the dateDiff function and setting answer equal to the number of seconds you want the timer to wait.



var theEnd = current.variable_pool.deployment_date;
var waitSecs = gs.dateDiff(gs.nowDateTime(), theEnd, true);
answer = waitSecs;


That would work most of the time but I expect the need for them to be able to change it if they decide to deploy earlier than originally stated.

I also thought about using a loop with a timer, but then we start running into issues with the max activity count getting hit.


Blair5
Tera Guru

James, Have you found a solution for this? I have almost the same use case that I'm trying to figure out.


Admin Pro
Tera Contributor

James,
Have you found any better solution for this issue?