Wait for condition Script in workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2018 07:47 AM
Hi all,
I have wait for condition and it should work when the status is 'closed complete' or 'closed incomplete' or 'closed skipped'. But my script is not working and my tasks are in parallel. But I can't use join.
Below is my script :-
checkCatalogTasks();
function checkCatalogTasks() {
var grTask = new GlideRecord('sc_task');
var Task = gr.addQuery('request_item', current.sys_id);
Task.addOrCondition('active', true);
Task.addOrCondition('state', '!=', '3');
Task.addOrCondition('state', '!=', '4');
Task.addOrCondition('state', '!=', '7');
grTask.query();
if(grTask.hasNext()){
answer = false;
}
else{
answer = true;
}
}
Please help. Thanks in advance.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2018 07:54 AM
Instead of using addorcondition why don't you do something like.
grTask.addQuery('state', 'NOT IN', '3,4,7');
I also don't think you need to check if that task is active because it would never be active once that state is closed. So it would look like this instead.
checkCatalogTasks();
function checkCatalogTasks() {
var grTask = new GlideRecord('sc_task');
grTask.addQuery('state', 'NOT IN', '3,4,7');
grTask.query();
if(grTask.hasNext()){
answer = false;
}
else{
answer = true;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2018 05:04 AM
Also instead of if (grTask.hasNext()) try if (grTask.next())

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2018 08:01 AM
Hi Madhu,
If it is not your typo here, below is something you need to modify.
Replace gr with grTask in line4 of your script.
Also, may I know why you are using Task variable while you already have grTask variable?
Hope this helps!
Thanks,
Archana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2018 08:04 AM
Hi Madhu,
Instead of using script, you can make use of the check box "wait for completion"
I have attached a screnshot for reference.