The CreatorCon Call for Content is officially open! Get started here.

IF Script to check whether all the Tasks are in "Complete" state

sanithakavungal
Giga Contributor

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

1 ACCEPTED SOLUTION

//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;


}


}


Regards
Harish

View solution in original post

4 REPLIES 4

Hi harish,



This is not working.



I need a condition to check whether all the generated Tasks have been closed Complete.



Regards,


Sanitha


//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;


}


}


Regards
Harish

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!