Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
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.

Labels (1)
8 Replies
marcus_sommer
MVP
MVP

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
MVP
MVP

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
MVP
MVP

Maybe:

function getVariable(varName) {

  var doc = ActiveDocument;

  var vget = doc.Variables(varName);

getVariable = vget.GetContent.String;

}

- Marcus

Not applicable
Author

No luck

marcus_sommer
MVP
MVP

Maybe this more helpful: Read QV-Variables via JavaScript

- Marcus