Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Using Variable with GetFieldSelections() in the script

Hi!,

I am trying to create a new table from the filters selected in a sheet and using this variable:

vSelections=GetFieldSelections(machine_PO)

The problem is that the script interprets the variable as: ' GetFieldSelections ( machine_PO )' and not as its text value
such as ' Machine11 ' .
I have the following in the load :

load

code,

machine,

time

resident Production

where machine=$(vSelections);

I tried also with ' $ ( vSelections )' but still does not work .


I am using a qlik sense desktop.

Any possible solution ?

7 Replies
swuehl
MVP
MVP

GetFieldSelections() is front end only function and can't be used in the script.

So you would need to create a variable that holds the value (and not the function to retrieve the value).

In QV, we could use triggers and an action to set the value 'Machine11' to a variable.

In QS, I don't think we have these means.

Hm, not sure how to resolve this (I still haven't looked very deep into QS).

Maybe mto‌ has a good advice?

Michael_Tarallo
Employee
Employee

Hi Guys,

Like this ? - see sample attached app.

You can do this using the new variables interface:

Qlik Sense - Variables Interface (video)

As Stefan pointed out - GetFieldSelections is a client side, object expression - and not meant to be run in the load script.

Please copy .qvf file to your C:\Users\<user profile>\Documents\Qlik\Sense\Apps and refresh Qlik Sense Desktop with F5

Let me know how you do.

Please mark the appropriate replies as CORRECT / HELPFUL so our team and other members know that your question(s) has been answered to your satisfaction.

Regards,

Mike Tarallo

Qlik

Regards,
Mike Tarallo
Qlik
Not applicable
Author

Hi,

Firstly thanks for the answers.

Michael what I really need is to use (vSelection) as a filter in an expression like:

Load

code,

machine,

time

resident Production

where machine=$(vSelections);

But as you say , the GetFieldSelections function can not be used in the script. So, I would  need to get a variable with the textual value resulting from (vSelection) .But this is probably not possible.


Thank you again.

Michael_Tarallo
Employee
Employee

Hi Isaac,  I guess I would need to know more about what you are trying to do, and the usecase. Because technically we don't work like a SQL query tool. All the data is loaded from the source into the app and then is on the fly filtered using the client interface and selection objects in the app. It seems to me you are trying to limit the data loaded into the app based of of a previous selection. This still may be possible, but I am not sure how - I added a colleague, whom if he has a moment might respond as well.

jpe

Regards,
Mike Tarallo
Qlik
Not applicable
Author

Hi,

I will try to expose the use case in question.
From a main table ( Production) , with the following fields :
Codigo_OP ( Orden Produccion )
Machine ( Maquina )
Item ( Pieza)
RealBegin(Fecha Inicio Seleccion)
RealEnd(Fecha Fin Seleccion)
I create another new table ( Production_timeline ) only with machines that have worked within the specified date range , using for this the Reload extension.
( This is necessary because google api I'm using does not allow Measures )

Then the table ( Production_timeline ) is shown in the timeline and chart table.
Well, what the customer really wants is to select date range and machine and make a new reload with those filters and for this I need to know which machine is selecting , but  with GetFieldSelections () as you have said is not possible.

I hope I explained , but ask me anything.

Thanks again for allscreen.PNG

JonnyPoole
Former Employee
Former Employee

instead of getfieldselections([Field]) i usually suggest using concat() instead.

Concat( distinct  [Field]  , ';' )  ...will create a ; delimitted list of [Field] values in the possible current state. 

you could use a single quote character as well

chr(39) & Concat( distinct  [Field]  , chr(39) & ',' & chr(39) )  & chr(39)


... this would create a string like this :     'Canada','USA'

Not applicable
Author

Hi Jonathan,

I tried your solution , but I still have the same problem:

Maquina=chr(39) & Concat( distinct (Maquina) , chr(39) & ',' & chr(39) ) & chr(39)

I still do not get the textual dimension value in a variable.
Thanks anyway for your answer.