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

flow designer - scripted wait for condition , wait for catalog task to be closed complete

cnshum
Tera Contributor

Hi 

 

I am trying to implement a scripted "wait for condition" that checks whether catalog tasks generated for a particular stage is "closed complete" before moving on to the next stage.

 

By stage I mean the below, do note that I am dynamically generating these tasks and stages (no hard coding). Do note that all tasks for each stage needs to be in "closed complete"  before moving to the next stage. Tasks in each stage are generated in parallel.

stage 1:                            stage 2:                         stage 3:

catalog task 1                  catalog task 3              catalog task 4

catalog task 2                                                        catalog task 5

 

cnshum_1-1713356270048.png

 

 

 

 

step 24: generates catalog tasks dynamically

step 25: after generating the catalog tasks for a stage, I check whether there are any tasks that are not in "closed complete". 

cnshum_2-1713356466132.png

step 26: If the number of records > 0 , means there are tasks not in "closed complete" 

step 27: scripted wait for 

cnshum_3-1713356625374.png

 

This is my scripted wait for, I basically look for sc_tasks that belong to the RITM that are not "closed complete" and sets the answer = false to wait.

 

var reqItem = fd_data.trigger.request_item.sys_id;
var gr = new GlideRecord("sc_task");
gr.addEncodedQuery("state!=3^request_item=" + reqItem);
gr.query();
gs.info("flow designer row count: " + gr.getRowCount());
if(gr.getRowCount() > 0){
    answer = false;
}
else{
    answer = true;
}
}
 
But the issue is , the scripted wait for does not wait , it just creates task for the next stage. 

 

 

 

13 REPLIES 13

Hi 

 

All I did to resolve that error was to write the true and false as a string variable instead of boolean and the entire approval flow works

Hi cnshum,

I am trying to do something similar via code, but I am finding the Wait For Condition continues regardless.

I have a very simple catalog item with 1 variable.

My Wait for Condition is a script that gets that Item, checks to see the value of the variable and returns a true/false 

As you did, I found that if I do not return a string of "true"/"false" it will fail.

I have added logs into the script and I can see the logic is correct and it returns the correct thing, but no matter what, I am always seeing it complete.  Any ideas ?

I have tried creating an answer variable and making sure that is the last line in the script - as that used to be a requirement years ago

 

JulianP32954866_0-1731091029892.png

 

var answer = "false";
var reqItem = fd_data.trigger.request_item.sys_id;
gs.info('JP : sys_id : ' + reqItem)
var gr = new GlideRecord("sc_req_item");
gr.get(reqItem);
gs.info('JP : ' + gr.number)
if(gr.variables.test == "No"){
    gs.info('JP : false : '+ gr.variables.test)
} else {
    gs.info('JP : true : '+ gr.variables.test)
    answer = "true";
}
return answer;

Community Alums
Not applicable

I have a solution for this, but not sure if it will apply to your use case. Flow designer is not friendly to dynamically creating tasks the way that workflow editor is because of the limitations on scripting a wait for condition. That is something that really needs to be enhanced. To get around this, you will have to do 1 of 2 things. If your flow does not have more actions to complete that are independent of the dynamic catalog task creations, do this:

 

1. Create a subflow that will be used to create your catalog tasks. Uncheck the wait for on the subflow creation. Pass all necessary information to this subflow. Pass the number of catalog tasks that you will be dynamically creating. This will be used to know when all tasks have been completed. 

2. Add a variable on the catalog item that will be used to keep count of the number of catalog tasks that have closed.

3. Create a UI Policy to hide that variable.

4. Create a custom action that will update the count on the catalog item. Pass in the RITM SysID as your input.

      

austin_curry_0-1713364486171.png

 

5. After your catalog task is complete in the subflow, run the above action.

6. Get Catalog Variables, get the hidden variable counter value.

7. After running that action, add an if statement to check if the number of catalog tasks to be created(that was passed into your subflow) equals the number in your hidden variable field. If it is equal, you know that all catalog tasks have been completed.

 

 

The way to do this if you are needing to run additional actions that are independent of your catalog tasks would be to add a field to the RITM table to track the number of closed tasks. Then set up your wait for condition to wait for that field to equal the number of catalog tasks that are dynamically created.

can hit too many loops doing that, which is why Wait For Condtion is useful