The CreatorCon Call for Content is officially open! Get started here.

String array in flow designer

arjun0101
Tera Contributor

Hi , 

 

I am working flow designer , i have declared one string type flow variable. it has values separated by comma.

like var v= 'str,pqr,atf';

i want to runfor loop to iterate this values. Anybody can help here ?

 

6 REPLIES 6

Prana Krushna
Giga Guru

Hi,  you can create an action to convert that string to array. i am attaching an referral screen shot i have done

PranaKrushna_0-1731671887837.png
I have passed that flow variable as input to action to convert it into array and return that as an array and then i can user foreach to loop that array

 

The input of that action will be a string and output of that action will be an array.

 

You can try. if you have issue you can reply.

 

If it helps mark this as helpful.

 

Animesh Das2
Mega Sage
Mega Sage

Hi @arjun0101 ,

 

You need to create another flow variable (for example, 'variable test') and use 'Set Flow Variables' flow logic to set the value of the string flow variable with 'Split' transform function in it (1st SS shown below). Now your 'variable test' flow variable should have the array.

Once you have the array you can use the 'For each item in' flow logic to run a loop using the array flow variable ('variable test' variable in my example) in items field. (2nd SS shown below).

 

 

AnimeshDas2_1-1731693808016.png

AnimeshDas2_3-1731694113978.png

If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

 

Hi @arjun0101 ,

 

If you got chance to check the solution and if it worked,

Please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

Tejas1018
Tera Contributor

Hi arjun0101 ,

You can use the .split() method to separate the string and convert it into an array, making it easier to apply a loop with the array.Try with following code.

 

// Example string variable
var v = 'str,pqr,atf';

// Split the string into an array using the comma as a delimiter
var valuesArray = v.split(',');

// Iterate over the array using a for loop
for (var i = 0; i < valuesArray.length; i++) {
    // Access each value using the index
    var value = valuesArray[i];
    // Do something with the value (e.g., log it)
    gs.info('Value: ' + value);
}

 

 Thank You...!