Skip to main content
Solved

Create a list of variables for FSM mobile

  • September 28, 2022
  • 4 replies
  • 156 views

Forum|alt.badge.img+9
  • Sidekick (Customer)
  • 49 replies

Hi All,

 

I’m struggeling to create a list via a Mobile Client Script.

  • I succesfully recieve a Object with data via getDBValues, but I only need one item from that object.
  • So I created a for loop, to go trough the object and store the value in a String, Array or Object (doesn’t matter).
  • Creating a new Array or a Object seems not to work for mobile
  • Als simply extending a var via the += method also not working.

Example:

var data = getDBValues(stringFormat("SELECT id FROM database_table WHERE type = 'placeholder'"));
var arr = new Array();
var list = ‘’;

for(var i=0; i < data.length; i++) {    
   arr.push(data[i]['ID']);
   list+= data[i]['ID'];
}

 

Best answer by nimesha.kalinga

Hello @Shneor Cheshin 

It will show the ID’s, but now the variable will only contain the last value from the loop. 
In the end I would like to have the variable “myID” containing all ID’s from the loop. 

 

 

Hi @drooij 

 

Can you try the below,

var strListOfId = "";

for(var i = 0; i < size(data); ++i) {
var myID = data[i]["id"];
strListOfId = stringFormat("{0}, {1}", strListOfId, myID);
}

alert(strListOfId);

apologize for the syntaxes as i haven’t had time to test it. But your requirement should be possible with using the stringFormat function

4 replies

Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • 1183 replies
  • September 28, 2022

Hey @drooij 

Can you try the following?

In the for loop, try printing the values. And remove the array creation, for now

for(var i = 0; i < size(data); ++i) {
var myID = data[i]["id"];
alert(myID);
}

What are the results?

Cheers!


Forum|alt.badge.img+9
  • Author
  • Sidekick (Customer)
  • 49 replies
  • September 28, 2022

Hello @Shneor Cheshin 

It will show the ID’s, but now the variable will only contain the last value from the loop. 
In the end I would like to have the variable “myID” containing all ID’s from the loop. 

 


Forum|alt.badge.img+4
  • Do Gooder (Employee)
  • 7 replies
  • Answer
  • September 28, 2022

Hello @Shneor Cheshin 

It will show the ID’s, but now the variable will only contain the last value from the loop. 
In the end I would like to have the variable “myID” containing all ID’s from the loop. 

 

 

Hi @drooij 

 

Can you try the below,

var strListOfId = "";

for(var i = 0; i < size(data); ++i) {
var myID = data[i]["id"];
strListOfId = stringFormat("{0}, {1}", strListOfId, myID);
}

alert(strListOfId);

apologize for the syntaxes as i haven’t had time to test it. But your requirement should be possible with using the stringFormat function


Forum|alt.badge.img+9
  • Author
  • Sidekick (Customer)
  • 49 replies
  • September 28, 2022

Hi @nimesha.kalinga,

 

Thanks, that worked!