cancel
Showing results for 
Search instead for 
Did you mean: 

SAC Scripting: Defining/Using JSON objects in functions

mitko1994
Participant

Hello,

I was wondering how to work with JSON objects and how to pass them around in functions. I don't see Object as a data type for functions and variables. I know that in pure JS, JSON.parse() and JSON.stringify() are used to convert a string to a JSON and a JSON to String respectively. Therefore you can use a string as an input/return type and just parse the JSON object when you need to work with it. How can I achieve this in a function inside an Analytical Application. I tried looking up the API reference and this handbook without success. I need an object that will hold exchange rates w.r.t Euro like so: {"USD": "1.073", "CAD":"1.515"} and I would like to store this object in a variable (maybe as a string) and manipulate the parsed object.

Thanks,

Dimitar

0 Kudos

Hello Dimitar,

Did you find a way to achieve it ?

mightz
Explorer
0 Kudos

Hey,

I am using some kind of an JSON or Object variable:

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

then you can read it like this:

for(var y=0;y<charts.length;y++){
	
	//loop over available measures
	for (var j = 0; j < measures.length; j++) {
	
		//define item object
		
		var item={};
	
		for (var itemKey in measures[j]) {
			item[itemKey] = measures[j][itemKey];
		}
	
		//loop over available measures
		
		if (dashboardVersion === item.type) {
			charts[y].addMeasure(item.id, Feed.ValueAxis);
		}
	};

}

Hope it helps.

Hint: You can store this kind of variables as global Variable by using "Selection" as a type

BR

Accepted Solutions (0)

Answers (0)