Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
RSvebeck
Specialist
Specialist

Help with GetAllVariables(callbackFn(object[]))

Hi


How can I write if I want the GetAllVariables(callbackFn(object[])) function to retrieve the value in a variable called "vGetColor1"?


I have tried all sorts of things but I can not get anything to work.


The example in the API is like this:


Init = function() {
var mydoc = Qv.GetCurrentDocument();
mydoc.GetAllVariables(function(vars) {
for (var i = 0; i < vars.length; i++) {
var obj = vars;
var name = obj.name;
var value = obj.value;
}
});
}


This works good, and will loop through all variables in my document. I have tried to write an "IF (name = "vGetColor" ...) in there, but this value seems to exist only inside the function and I can't get it stored into a global JScript variable for some strange reason...


What I'm looking for is a function something like this:


function GetValueFromVariable(VariableName).
{
var mydoc = Qv.GetCurrentDocument();
return mydoc.GetAllVariables(function(vars) {
for (var i = 0; i < vars.length; i++) {
var obj = vars;
var name = obj.name;
var value = obj.value;
if (name==VariableName) return value;
}
};


However, this does not work. All I get back from my function is "Undefined"....


Please help me...


Regards Robert

Svebeck Consulting AB
1 Solution

Accepted Solutions
Not applicable

I do not know what you are trying to achieve but if your variable name is fixed you could add a Text or RefValue to your extension by adding this line in your definition.xml :

<Text Initial="" Expression="=YourVariable" />

or

<RefValue Initial="" Expression="=YourVariable" />

Then you'll be able to retrieve your variable value in this.Layout.Text0.text or this.Layout.RefValue0.value.

View solution in original post

2 Replies
Not applicable

I do not know what you are trying to achieve but if your variable name is fixed you could add a Text or RefValue to your extension by adding this line in your definition.xml :

<Text Initial="" Expression="=YourVariable" />

or

<RefValue Initial="" Expression="=YourVariable" />

Then you'll be able to retrieve your variable value in this.Layout.Text0.text or this.Layout.RefValue0.value.

RSvebeck
Specialist
Specialist
Author

Thanks, that works! /Robert

Svebeck Consulting AB