Script for IF 0 tasks in stage "Account Level" move state to complete.

HenryD
Tera Guru

Hello, im working in wf editor & i need a script for if there are sc_tasks that contain stage "Account Level" and have 0 tasks, i need the wf to be connected to an activity called "set values" RITM Closed completed. I have the set values, but the script is causing me a headache, can anyone help please or any tips. 

3 REPLIES 3

DrewW
Mega Sage
Mega Sage

If this is a workflow then you can just use a "Wait for condition" activity and return false if your script finds the records you are looking for and true if no records found,

 

//This is what we use in a "Wait for condition" activity.
answer = (function(){
	var gr = new GlideRecord("sc_task");
	gr.addQuery("request_item", current.getValue("sys_id"));
	gr.addActiveQuery();
	gr.query();
	if (gr.next())
		return false;
	else 
		return true;
})();

 

If this is for a flow its a bit more involved.  For flow designer you need to use a subflow.  Here is a screen shot of ours.

DrewW_0-1711487160673.png

 

Hi drew, i have a wait for conditon already to wait for the approver to either approve or send back to prior stage, would i neeed to build this ontop of it? or can i use a script for an IF it has no tasks in account level than to close complete 

Since I don't know the whole story its difficult to know if you should do that or add another activity.  But my first thought is add it after you have decided approval that way its clearer what the workflow is doing.