- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 05:24 AM
Hi Team,
I written following code in "wait for condition" in work flow to pause the workflow until to close all task records for particular request item, But this not working, even all the tasks are closed but still it is in wait for condition only. It is not moving to further activities.
All these tasks are created dynamically trough run script from inputs of list collector.
Any Idea or inputs can help me a lot
code:
var gRT = new GlideRecord('sc_task');
gRT.addQuery('request_item',current.sys_id);
gRT.addQuery('active',true);
gRT.query();
if(gRT.hasNext()){
answer = false;
gs.log('if'+gRT.hasNext());
}
else{
answer = true;
gs.log('else'+gRT.hasNext());
}
Thanks.
Developer CommunityDiscussExperts CornerCommunity CornerConnect
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 07:54 AM
That's a good point. Workflows only re-check when the record used against the workflow (e.g. RITM, change request) is updated. Updating child records isn't going to trigger the workflow on the parent record. To do this, you could force an update on the request_item when an update to the sc_tasl table is made.
An AFTER BR on the sc_task table something like this
(function executeRule(current, previous /*null when async*/) {
var parent = new GlideRecord('sc_req_item');
parent.get(current.request);
parent.setForceUpdate(true);
parent.update();
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 05:32 AM
Hi Abhay,
Have you tried using a GlideAggregate to count instead of checking if there is a next record? For performance reasons, this is a better idea.
(Untested) example:
var gRT = new GlideAggregate('sc_task');
gRT.addAggregate('COUNT');
var count = -1;
gRT.addQuery('request_item',current.sys_id);
gRT.addQuery('active',true);
gRT.query();
if (gRT.next()) {
count = gRT.getAggregate('COUNT');
}
gs.log('found ' + count + ' records');
answer = (count == 0);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 05:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 06:14 AM
Hi Chuck,
Thanks for your quick reply, I tried using your code, It is not working.
Trough log i found that count remains 2(I opened two tasks) even after I closed first task and checked, it is not updating. it is not generating any new log of new count value. the value remains 2 only. I hope some thing is not triggering the" wait for condition " to check when i update the tasks. Is there any business rule that will trigger the workflow or resume the workflow to check the "wait for condition" again.
any Inputs will help me a lot
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 06:17 AM
Hi Abhay,
Did you try my code and print log and check how much count you receive and let me know if any concerns.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 06:22 AM
Have you tried the GlideAggregate example I posted earlier?
Best practice recommends using GlideAggregate if you are simply counting records.
Another option would be to limit the amount of records queried using
gRT.setLimit(1);
That will make the gRT.query() run quicker since you really only want to know if there are 0 or non-zero results.