Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
valerio_trotta
Contributor III

Pass variable from front-end to loading script

Hi everyone,

 

can i let a user define the value of a variable from the front-end of QlikSense and than use that same variable in the loading script?

For example, let's say that i want to give the user the possibility to filter the all loading of a table by setting a year (silly example i know). Ideally i would let the user define the year inside a variable, then can i use it to filter a table in the loading script?

 

I'm developing the app o Desktop but i would like to bring it to the enterprise system.

 

Thank you

VT

Labels (3)
7 Replies
Kellerassel
Contributor III

Yes, that works. You can define a variable either inside the script or in the variable editor of the front-end and allow the user to enter a value by putting a Variable Input object from the Qlik Dashboard Bundle. 

Then also add a Button object and assign it the action Reload Data.

In your script you need a query along the lines of:

/* Set vYourVariable = SomeValue; */


YourData:
Load *
;
SQL SELECT *
FROM your_table
WHERE your_field = '$(vYourVariable)'
;

 
Every time the button is clicked the script will be executed and data will be loaded according to the current value of vYourVariable. If you create the variable in the script, don't forget to comment out the statement after the first run of the script otherwise the users setting will always be overridden.

SunilChauhan
Champion II

Take input box and Button . in Inputbox set Variable at front. on Button allow reload action.

Sunil Chauhan
Tool_Tip
Creator III

How about doing it reverse way?

We have sql query with input variable parameter. We want to keep the query as it is and on front end we want to have some variable to be accepted same value as the variable defined in the query

robert_mika
Master III

How is your variable defined?

Tool_Tip
Creator III

We have defined variable as 

Let vYear='202412'

 

And we have used this variable in query as 

Select *

from table1

were YearMN='$(vYear)'

 

After loading from load script we are getting the resultset for vYear=202412 but instead of it we want to keep variable on fronend where we can provide input as in requirnemnt such as 202412,202411,202401 etc. and then this front end input variable value needs to be applied on load script query...

Lech_Miszkiewicz
Partner Ambassador/MVP

Hi @valerio_trotta 

If your question is - can you select variable value from UI and pass its value to script on enterprise (published) app? - NO - you can't!

If others would do the same amount of testing as I did they would be careful with their answers i think. If what they just said was possible in the past everyone would use that as workaround for write back solution!

Script which is run in the background when app is published runs under "scheduler" user so desipite it may work when you have app in your work stream or in QS desktop it will not work when you publish the app as variable value belongs to user holding a sesion and not doing a reload. That may look like its working if you are the owner of the app but in reality it is not.

As others suggested you can have variable declared in script and you can create and read its value from external sources like cell in spreadsheet or text file and that is the easiest you can get 

cheers

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
howdash
Creator

I second @Lech_Miszkiewicz reply. Passing variable values from front-end to the script in a published app is not possible.

The closest thing to passing a variable value from front-end to be used in a script during reload is On-Demand App Generation (ODAG) feature of Qlik Sense.

Although, if you’re not working with a big dataset and instead just need to show a single date at a time, for example, I recommend using the Always One Selected Value feature instead of setting up ODAG.

When working with a small dataset, you can load all data in the app, set the YearMN field to have always one selected value, and then just let the users choose which one year and month they would like to see from the front-end.