Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Wait for condition script in the subflow

Negha1
Tera Contributor

Hi,

 

I have a requirement like RITM creacte sctask, need to wait until myself or some allowed users updated the worknotes where i created a flow action to return worknotes updated is true or false -- which is working fine , it returns true or false as string and task sys id and task number, where input is ritm sys id.

 

But the main requirement is if worknotes updated by allowed users ---- true, then flow has to continue

if false then need to wait until becomes true

but this i have to do it in subflow... in wait for condition, record  i gave flow action--task sys id in the record field

and script i gave 

(function(fd_data) {

    // Get the latest output from your Flow Action
    var worknoteFlag = fd_data.action['Check allowed user update worknotes'].outputs.worknotes_updated;

    if (worknoteFlag === true) {
        return true; // Continue flow
    }

 

Negha1_0-1763030831378.png

 

let me know if i done wrong, suggest me the way to achieve this.

 

iam getting error while testing Error: "fd_data" is not defined.,Detail: "fd_data" is not defined. let me know if script need to be modified and how?

3 REPLIES 3

SD_Chandan
Kilo Sage

Hi @Negha1 ,

After your custom Flow Action (Check allowed user update worknotes), map its output (worknotes_updated) to a variable.

or 
Data Pill approach
{{Check allowed user update worknotes.outputs.worknotes_updated}} is true



Thank you
Chandan

Nawal Singh
Tera Guru

Hi @Negha1 ,

if your Flow Action outputs the Task Sys ID, you can use that to set the record in “Wait for Condition”.

Example:

Record = Check allowed user update worknotes.outputs.task_sysid
Table = sc_task

Then your Condition Script should look like this:- 

 

if (current.u_worknote_flag == true) {
        return true; // continue the flow
    }

    return false;

 If you found my response helpful, please mark it as helpful and accept it as the solution.

Thank you
Nawal Singh

Brad Bowman
Kilo Patron
Kilo Patron

You can just use the data pill from the action in the Condition without a script.  If you choose to script, the syntax is incorrect.  When you type fd it should prompt for fd_data, then when you type a period it should show the next valid choice, which would be like _2__check...  It's probably not prompting, and giving the error, because the Table is not populated, because the Record is probably incorrect.  You need a record object, not a sys_id.  If you only have the sys_id you need to use that in a Lookup Record activity, then use that activity to check a field.

 

With this approach, I think you would need a do until loop following the #2 action, until the action worknote flag = 'true'.  The step in the loop is simply a timer to wait a minute, hour, day... whatever seems like it would work without hitting the maximum loop count allowed before it's updated.

 

Another approach might be to not return false in the action, do the loop there to wait until it's true, then this flow/subflow doesn't need to wait.  There's probably other possibilities, maybe a better approach if I more understood all of the flows, subflows, and actions involved here.