Workflow Wait for Condition

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2010 11:56 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2017 01:02 PM
When I came across this article yesterday, It had been almost a year since the last post. I'm running Istanbul, P1.
The post was exactly what I needed. Before adding the script to my timer activity, I looked to see if there wasn't an alternative. I have been able to accomplish my workflow wait condition with a timer activity via point and click. I have a table/form with a "Send date and time" field. The action is to send a notification upon reaching the established date and time. I believe this is the same request initiating the thread. Below is an image to the timer activity.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2018 09:57 AM
Having similar issue with Demand Management. Using workflow wait for condition to wait for all resource plans to be allocated. Here is the wait for activity scrip (The workflow runs agains dmn_demand table, so I query resource_plan, looking for those that have the sys_id of the demand in the task field)
//Query for all resource plans to see if they are requested
var rec = new GlideRecord('resource_plan');
rec.addQuery('task', current.sys_id);
rec.addQuery('state','!=', 3);
rec.query();
if(rec.hasNext()){
answer = false;
}
read that wait for condition does not check until the record that the workflow is running on is updated, in this case the demand, so I figured I would write to the work notes on the demand indicating that the resource plan was updated. This is an after update business rule with a condition that state changes to Allocated:
(function executeRule(current, previous /*null when async*/) {
var demand = new GlideRecord("dmn_demand");
demand.addQuery('sys_id', current.task);
demand.query();
if(demand.next()) {
var msg = "Resource Plan: " + current.number + " " + current.short_description.getDisplayValue() + ":Allocated";
demand.work_notes = msg;
demand.setForceUpdate(true);
demand.update();
}
})(current, previous);
I am getting the work notes updated on the demand, however the workflow does not advance, so I added the following to nudge via the same business rule. However, it still does not advance the workflow. I am seeing the correct demand in the script log from the gs.log() statement.
(function executeRule(current, previous /*null when async*/) {
var demand = new GlideRecord("dmn_demand");
demand.addQuery('sys_id', current.task);
demand.query();
if(demand.next()) {
var msg = "Resource Plan: " + current.number + " " + current.short_description.getDisplayValue() + ":Allocated";
demand.work_notes = msg;
demand.setForceUpdate(true);
demand.update();
//gs.log("****got here****");
var wf = new Workflow();
var gr = new GlideRecord("dmn_demand");
gr.addQuery('sys_id', current.task);
gr.query();
while(gr.next()) {
gs.log("Triggering workflow for: " + gr.number);
wf.runFlows(gr, 'update');
}
}
})(current, previous);
If I go into the record and add work notes it advances, not sure why the business rule that is basically doing the same thing does not advance the workflow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 05:15 AM
Found that my issue was related to business rule. After further review, found that I did not set after update. It was set before update, which caused my issue. After changing, things worked as expected.