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: 
Not applicable

Get and Set variable functions in JScript

Does anyone know what is the correct code for getting and setting variable value in JScript?

I use the following code which is not working (obviously):

function getVariable(varName) {

  var doc = ActiveDocument;

  var vget = doc.Variables(varName);

getVariable = vget.Value;

}

function setVariable(varName, varValue) {

  var doc = ActiveDocument;

  var vset = doc.Variables(varValue);

  vset.SetVariable(varName, varValue);

  doc = null;

}

Thank you very much in advance.

8 Replies
marcus_sommer

Try something like this:

function setVariable(varName, varValue) {

  var doc = ActiveDocument;

  var vset = doc.Variables(varName);

  vset.SetContent varValue;

  doc = null;

}

Not applicable
Author

It fails to parse. Unless I change this vset.SetContent varValue;

to this vset.SetContent (varValue);


But that doesn't help as well...

marcus_sommer

Maybe this is helpful: JavaScript Function in WebView

- Marcus

Not applicable
Author

Thanks Marcus. Unfortunately, not.

Not applicable
Author

Some modifications and setVariable works, but how to make getVariable work?

function setVariable(varName, varValue) {

  var doc = ActiveDocument;

  var v = doc.Variables(varName)

  v.SetContent(varValue, true);

}

marcus_sommer

Maybe:

function getVariable(varName) {

  var doc = ActiveDocument;

  var vget = doc.Variables(varName);

getVariable = vget.GetContent.String;

}

- Marcus

Not applicable
Author

No luck

marcus_sommer

Maybe this more helpful: Read QV-Variables via JavaScript

- Marcus