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.

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

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.

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);
}

Community Alums
Not applicable

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. try with this 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);
}