Script in Wait for Condition - Flow Designer shows error

Anu2
Tera Contributor

I am trying to write a script to check for any open change tasks and return true or false in Wait for Condition in flow designer.
But the Wait for Condition is showing error every time. Even if write a simple statement [return true] without any other code, the activity still shows error.
The subflow input is change request record and below is the Wait for condition to check for any open change tasks.

Anu2_0-1728353369475.pngAnu2_1-1728353389433.png

Please suggest if any idea?

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hello @Anu2 

The wait for condition script expects an encoded query as return value (for example "active=true^change_request=..."), not just the true false. I don't think wait for condition fits in your requirement.

 

Please ckarify your requirement, like you want to wait until all the change tasks are closed to continue further, OR just check if there is any open tasks or not and the continue accordingly. Based on your requirement I can provide a solution here.

 

If you want to wait until all the open tasks are closed, follow the screenshots below.

1. Sub flow with input type of Reference to Change Request

 

AnveshKumarM_0-1728374700545.png

 

2. Create a flow variable.

AnveshKumarM_1-1728374800766.png

3. Set flow variables - Check box unchecked - means False

AnveshKumarM_2-1728374862494.png

4. Use a Do.. While loop

AnveshKumarM_3-1728374999863.png

 

5. In the loop, have these actions.

AnveshKumarM_4-1728376425106.png

AnveshKumarM_5-1728376468410.png

AnveshKumarM_6-1728376506185.png

AnveshKumarM_7-1728376546286.png

AnveshKumarM_8-1728376572965.png

AnveshKumarM_9-1728376715278.png

 

Please let me know if you need any help 🙂

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Thanks,
Anvesh

View solution in original post

7 REPLIES 7

Amit Verma
Kilo Patron
Kilo Patron

Hi @Anu2 

 

Below post could be helpful to you :

https://www.servicenow.com/community/developer-forum/flow-designer-script-on-wait-for-condition-not-...

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Anu2
Tera Contributor

The conditions mentioned in that post is not helpful as in my case there might be few change task which  are created manually not only from flow, hence I need to query the change task table to see if any active tasks are left.

Hi @Anu2 

 

You need to return the Wait for Action condition an encoded query so that the conditions could be evaluated. In the final return statement, try returning an encoded query like below example instead of true and false -

return 'active=true^number=CTASK0010002^state=3';

 

It will wait for the condition to be satisfied to continue.

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Mr_X
Mega Guru

Hi @Anu2 ,

 

Please return true in if condition and in else block return false.

if(chg.next())

      return true;

 

Please mark as helpful if my solution works and don't forget to hit thumbs up button!