Skip to main content
Solved

Create a list of variables for FSM mobile

  • September 28, 2022
  • 4 replies
  • 148 views

Forum|alt.badge.img+9

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

drooij wrote:

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

View original
Did this topic help you find an answer to your question?

Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28

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
  • Sidekick (Customer)
  • 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
drooij wrote:

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
  • Sidekick (Customer)
  • September 28, 2022

Hi @nimesha.kalinga,

 

Thanks, that worked! 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings