- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2017 09:52 PM
Hi All,
I need to create an IF activity on Workflow to check whether all the Tasks on the RITM are in Closed complete status.
Please help..
Regards,
Sanitha
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2017 11:00 PM
//not tested
Assuming your workflow is on Request Item table
// Set the variable 'answer' to true or false to indicate if the condition has been met or not.
chkTask();
function chkTask()
{
var c =0;
var chk=0;
var ctk = new GlideRecord('sc_task');
ctk.addQuery('request_item',current.sys_id);
ctk.query();
c = ctk.getRowCount();
while(ctk.next())
{ if(ctk.state == "3") // Here we are checking, whether the state of task is closed, so "3" is the value of closed state, you can replace it accordingly.
{ chk=chk+1; } }
if( chk == c)
{
answer = true;
}
}
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2017 09:57 PM
Here you can find
Wait for Closure of all Tasks in Graphical Workflow - ServiceNow Guru
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2017 10:51 PM
Hi harish,
This is not working.
I need a condition to check whether all the generated Tasks have been closed Complete.
Regards,
Sanitha

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2017 11:00 PM
//not tested
Assuming your workflow is on Request Item table
// Set the variable 'answer' to true or false to indicate if the condition has been met or not.
chkTask();
function chkTask()
{
var c =0;
var chk=0;
var ctk = new GlideRecord('sc_task');
ctk.addQuery('request_item',current.sys_id);
ctk.query();
c = ctk.getRowCount();
while(ctk.next())
{ if(ctk.state == "3") // Here we are checking, whether the state of task is closed, so "3" is the value of closed state, you can replace it accordingly.
{ chk=chk+1; } }
if( chk == c)
{
answer = true;
}
}
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2020 08:03 AM
This code is missing a critical steps, first the function does not return any values and second the code does not set the answer variable of the if condition workflow activity.
First Fix:
answer = chkTask(); // Replace chkTask(); first line
Second Fix
return = 'yes'; // replace answer = true;
Regardless of these missing parts, I was able to resolve the issue I was looking at thanks to Harish's code, so thank you!