Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

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

Re: Get and Set variable functions in JScript

Try something like this:

function setVariable(varName, varValue) {

  var doc = ActiveDocument;

  var vset = doc.Variables(varName);

  vset.SetContent varValue;

  doc = null;

}

Not applicable

Re: Get and Set variable functions in JScript

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

to this vset.SetContent (varValue);


But that doesn't help as well...

MVP & Luminary
MVP & Luminary

Re: Get and Set variable functions in JScript

Maybe this is helpful: JavaScript Function in WebView

- Marcus

Not applicable

Re: Get and Set variable functions in JScript

Thanks Marcus. Unfortunately, not.

Not applicable

Re: Get and Set variable functions in JScript

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);

}

MVP & Luminary
MVP & Luminary

Re: Get and Set variable functions in JScript

Maybe:

function getVariable(varName) {

  var doc = ActiveDocument;

  var vget = doc.Variables(varName);

getVariable = vget.GetContent.String;

}

- Marcus

Not applicable

Re: Get and Set variable functions in JScript

No luck

MVP & Luminary
MVP & Luminary

Re: Get and Set variable functions in JScript

Maybe this more helpful: Read QV-Variables via JavaScript

- Marcus