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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
vindhya_giri
Creator II
Creator II

Variable from qvs file to qvw

Hello everybody,

In one of our apps, we have a macro in edit module as follows:

sub ExportRowCount2

set chart = ActiveDocument.GetSheetObject("CH113")

ActiveDocument.Variables("vNumRows2").SetContent chart.GetNoOfRows, true

end sub

And,  defined vNumRows2= $(vNumRows2) in the qvs  file where we define all variables.

I am calling this qvs file into the qvw. But when I am reloading the app, I am not able to see this variable in the variable overview.

Please advise on this.

Thanks!

1 Solution

Accepted Solutions
vlad_komarov
Partner - Specialist III
Partner - Specialist III

Vindhya,

The "vNumRows=$(vNumRows)" code defines a vNumRows as a "reference" to existing definition of the vNumRows variable.

It seems like strange approach, but it allows to keep the defined variable after reload.

Using "let vNumRows=1", for example, will reset this variable to 1 every time the app is reloaded.

Using the code above will allow you to keep the last definition of the variable in the file after the reload.

But this approach does not work until you define this variable the first time (otherwise it's reference to null: "vNumRows=NULL").

So, you have to create the new variable (vNumRows2) in the app's Variables Definition dialog first and than use the code like "let vNumRows2=$(vNumRows2)" in the script.

Hope it helps.

Vlad

View solution in original post

9 Replies
simospa
Partner - Specialist
Partner - Specialist

Hi,

can you provide a snapshot of code in which we can see the assignment?

In qvs you might to assign the value in this way:

SET vNumRows2= $(vNumRows2);

S.

vindhya_giri
Creator II
Creator II
Author

Hi Simone, Here are the screenshots. I have tried SET also but still I am not getting the variable in the app.

Script in edit module:

Untitled.png

qvs file:

Untitled.pngUntitled.png

Untitled.png

Thanks!!

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

A variable that is null at the end of the script will not get "promoted" to the variable overview. It will get dropped at script end.

So if the variable doesn't currently exist, you can't create it by referring to itself.

LET vNumRows = $(vNumRows)

So you will need to set it to something at least once. Perhaps set it conditionally.

LET vNumRows = if(len('$(vNumRows)')>0, $(vNumRows), 0)


-Rob

vindhya_giri
Creator II
Creator II
Author

Hi Rob,

In my case, the first vNumRows is visible in the variable overview and the vNumRows2 is not.

Please advise

Thanks!

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Re-Read my post and substitute vNumRows2  for vNumRows. I only used vNumRows as the example, I believe it's the same problem,

-Rob

vindhya_giri
Creator II
Creator II
Author

Hi Rob,

My concern is that when one of the variables is working, why not the other one? both of them are defined in the same way. Please refer to my screenshots in previous post. Also, there is another application with similar code in edit module and the similar variables in the qvs file. That application is working fine.

I am trying to figure out if I am missing any step. Can you suggest of any step that you think I am missing according to my screenshots?

Also, I tried to use the example which you suggested in your post, it is giving the following error when reloaded:

Untitled.png

Please advise

Thanks!

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Add some quotes to avoid the syntax error when the variable is null.

LET vNumRows = if(len('$(vNumRows)')>0, '$(vNumRows)', 0)


I can't tell you why one of your variables is working and the other doesn't. I can tell you that a variable that is empty in the script does not get promoted to the UI. And a variable that doesn't exist in the UI can't be set by

ActiveDocument.Variables("vNumRows2").SetContent


If you want to "fix" it, why not just define the variables once in the variable overview. Or just hard cod the variables in the script like:

SET vNumRows=1;


-Rob

vlad_komarov
Partner - Specialist III
Partner - Specialist III

Vindhya,

The "vNumRows=$(vNumRows)" code defines a vNumRows as a "reference" to existing definition of the vNumRows variable.

It seems like strange approach, but it allows to keep the defined variable after reload.

Using "let vNumRows=1", for example, will reset this variable to 1 every time the app is reloaded.

Using the code above will allow you to keep the last definition of the variable in the file after the reload.

But this approach does not work until you define this variable the first time (otherwise it's reference to null: "vNumRows=NULL").

So, you have to create the new variable (vNumRows2) in the app's Variables Definition dialog first and than use the code like "let vNumRows2=$(vNumRows2)" in the script.

Hope it helps.

Vlad

vindhya_giri
Creator II
Creator II
Author

Thanks Vlad.