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

Sujatha V M
Kilo Patron
Kilo Patron

@cnshum I would like to know, why aren't you using "Wait" checkbox on the catalog task activity because if you set it to "True" , it will wait until the task is closed and then move to next stage. 

 

SujathaVM_0-1713357977887.png

As per your stages, 

 

stage 1:                                                     

catalog task 1   (Wait = True, if sequential ; Wait = False, if parallel)                          

catalog task 2   (Wait must be "True")                                                     

 

stage 2:

catalog task 3 (Wait must be "True") 

 

stage 3:

catalog task 4 (Wait = True, if sequential ; Wait = False, if parallel)              

catalog task 5 (Wait must be "True")  

 

Post this you can cascade the state to RITM. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Hi as mentioned, I'm dynamically generating the catalog tasks using a loop. I'm unable to control which tasks to wait. All tasks in each stage is generated in parallel 

maroon_byte
Mega Sage

I dont think you need a script for conditions... You can do something like below:

 

maroon_byte_1-1713361024535.png

 

Note: I would suggest not to use state as a condition because a task can be skipped or cancelled and not closed completed.

Now for transitioning to various stages, try this trick:

  1. Add your stages in 'Flow stages' of the flow
  2. Above below Lookup records action, use 'Add a Stage' to set to stage 1
  3. Lookup records in sc_task table for your condition + Active = true with Order by Number and Max results 2
  4. Wait for them to close (Wait for condition until Active = false)
  5. Above below Lookup records action, use 'Add a Stage' to set to stage 2
  6. Lookup records in sc_task table for your condition + Active = true with Order by Number and Max results 1
  7. Wait for it to close (Wait for condition until Active = false)
  8. Above below Lookup records action, use 'Add a Stage' to set to stage 3
  9. Lookup records in sc_task table for your condition + Active = true with Order by Number and Max results 2
  10. Wait for them to close (Wait for condition until Active = false)

Regards,

Sharad

You're just hard coding the catalog tasks and stages. As mentioned I'm dynamically generating the stage and catalog tasks.