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

Then how are you creating the catalog tasks dynamically? How are they visually identified which dynamically created task is of stage 1 or 2 or 3?

And are the number of dynamically created tasks always the same? How does the number vary?

 

Its not hardcoding... its same as a workflow. In a workflow, you have to mention the stage while creating workflow activity. Only then the stage on RITM will be updated accordingly. Same here in the flow designer.

 

Sharad

Hi

 

The tasks are generated based on a lookup from a custom table

 

The table fields are

Catalog name, task name, task sequence 

 

For example 

Catalog A , task 1 , 0

Catalog A, task 2, 0

Catalog A, task 3, 1

Catalog A, task 4, 2

Catalog A, task 5, 2

 

So the sequence is the stage 

Stage 0 - task 1, 2

Stage 1 - task 3

Stage 2 - task 4, 5

 

If there is more than one task in a stage, the task are generated in parallel.

 

And the stages can be from 0 to any number. That's why I mentioned that you were hard coding when you said "set max result..."

 

@cnshum I have tried the scenario in my PDI,

 

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){
   return false;
}
else{
    return true;
}
}
 

 

Log Result from my PDI, 

SujathaVM_0-1713372429567.png

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

 

I get this error when I use your solution

 

cnshum_0-1713414913268.png

 

@cnshum Please check the last comment in this link. 

 

https://www.servicenow.com/community/developer-forum/how-to-script-in-a-wait-for-condition-in-a-flow...

 

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.