cancel
Showing results for 
Search instead for 
Did you mean: 

How to loop through an Array of Object in Application Designer

mightz
Explorer
0 Kudos

Hello,

I would like to create an Array of Objects of my measures in SAC Application designer and then loop thourgh them to check, which of them has to be hidden.

So first I have created an Array:

 var measures = [
	{
		type: "LC", 
		id:"13UW1NAV5H0KSOI7YHAWV3FPY", 
		descr: "PY TOTAL @ bud fx"
	},
	{
		type: "GC", 
		id:"13UW1NAV5H0KSOGFDOPPN4GM9", 
		descr: "BUD TOTAL @ bud fx"
	}
];

So far so good.

Now I would like to loop with the foor loop.

for (i = 0; i < measures.length; i++) {

}

But here I get an error message "Auto-type conversion isnt supported"

I tried to use the following method to define an array. BUt there is no Type "Object" available.

var measures = ArrayUtils.create(Type.Number);

Is there any otehr way to define Arrays? Or to loop of these kind of arrays.

Thank you for help in advance!

Accepted Solutions (0)

Answers (3)

Answers (3)

Vitaliy-R
Developer Advocate
Developer Advocate
0 Kudos

I think the error message was because you need to use `var` in the loop:

for (var i = 0; i < measures.length; i++) { }

Regards.

mightz
Explorer
0 Kudos

Hi Nikhil,

thanks for your help.

The idea is:

I would like to list a full list of measures within an array. Custom array, not from the datasource.

Then Loop through charts and tables and hide/show measures depending of the users selection, by using some attributes of my array, like "Type"

Br

HErmann

N1kh1l
Active Contributor
0 Kudos

Hermann,

Try something like below.

Add table to your SAC Application. You can hide it if you dont want to display it. Then use below code snippets to get the measure list.

Regards

Nikhil

var measures = Table.getDataSource().getMeasures();
if (measures.length > 0) { 

for (var i = 0; i < measures.length; i++)

{ console.log(measures[i].id);} // You can put your logic here...have put console.log as sample


For e.g If want to populate a dropdown with my measure list I can use something like below.

Dropdown_Measures.addItem(measures[i].id, measures[i].description); //Dropdown_Measures is dropdown to populate all measures in my data source.