Iterate a list in a flow action

cbarlock
Kilo Guru

I have a "Project" table that has a column called "Policies" that is a List of "Policy".  I wrote a flow whose trigger is the creation of a new Project.  The flow passes Trigger->Project Record->Policies to an action.  This action has an input named "policies" that is of type "List.Policy".  A script projects this list:

 

(function execute(inputs, outputs) {
    var policies = inputs.policies;
    outputs.policy_names = '';
    while (policies.next()) {
        outputs.policy_names += '<br/>' + policies.getDisplayValue();
    }
})(inputs, outputs);

 

This works fine if the list contains two or more policies, but if there is only one, no policy names are generated.  What am I doing wrong?

Thanks!

1 ACCEPTED SOLUTION

bishopx
Giga Guru

You are doing nothing wrong. This is known issue I have reported this to HI more than 8 months ago.
Still not answer on when it will be fixed. Seems it's not really a priority for ServiceNow team.

You need to the manual workaround:

if(inputs.policies.getRowCount() == 1){
  gs.info(inputs.policies);
}
else{
  while(inputs.policies.next()){
    gs.info(inputs.policies);
  }
}

 

Hope that helps

Jozef

View solution in original post

4 REPLIES 4

bishopx
Giga Guru

You are doing nothing wrong. This is known issue I have reported this to HI more than 8 months ago.
Still not answer on when it will be fixed. Seems it's not really a priority for ServiceNow team.

You need to the manual workaround:

if(inputs.policies.getRowCount() == 1){
  gs.info(inputs.policies);
}
else{
  while(inputs.policies.next()){
    gs.info(inputs.policies);
  }
}

 

Hope that helps

Jozef

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Chris,

you will have to convert the array of String to Array

please check below links for help

How to iterate an Array.String in the flow designer?

Flow Designer Foreach loop on Service Catalog List Collector variable type not identified as record ...

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

cbarlock
Kilo Guru

Thank you both!

Hi Chris,

So what was the solution/workaround

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader