Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to set a variable and read it later in the same trigger

Hi,

I try to change selections in listbox2 due to selections in listbox1.

To do so I created an onSelction trigger on listbox1 with the following actions:

  • get the current selection in listbox1 and set it to the variable vMySelection.
  • some changes...
  • change the selection in listbox2 to the value of variable vMySelection

But I always get the value that was set before the last execution of the trigger, not the value I set in the first action

When are variables in trigger evaluated and how can I work around that behaviour?

I use QV 11.2 and the solution has to work with the ajax client.

Thanks a lot

Klaus

11 Replies
Anonymous
Not applicable
Author

I know what you describe is a right pain, but unfortunately that is the way QlikView works.

stigchel
Partner - Master
Partner - Master

There is no order in trigger handling, I'm even convinced that all triggers that need to be handled use the same state as before any of the triggers were executed. So your solution with a variable does not work. But I can't imagine that you cannot do the changes you mention in one single expression, which you could use to do a selection in lb2 directly.

Not applicable
Author

It's not a problem between triggers, only 1 trigger with these 3 actions.

You are right, I can't do it in one expression, because the 2nd step is to get all entries of another level to ensure they are shown as well as the original selection

Any ideas how to store the selection elsewhere?

Not applicable
Author

I had exactly the same issue and got the response back from support:

'Actions are not carried out sequentially on buttons, they are all expanded and executed at the same time.'

That was in April 2010 and although I raised an 'idea' to provide an option to perform sequential processing, nothing came of it

The only alternative is a macro (shudder).

Regards,

Gordon

stigchel
Partner - Master
Partner - Master

I'm afraid there is some misunderstanding:

- Let me rephrase the bit about triggers: all actions in a trigger use the same state, you cannot use changes in the process

- I think you can do it in one expression, at least i cannot imagine why you could not

Can you explain what you mean by all entries of another level?

Not applicable
Author

I fear macros won't work in Ajax-Client

thanks for clarification about the execution order of actions

Regards,

Klaus

Not applicable
Author

we have flattened Hierarchie in a table.

In an extension this hierarchie is to be shown as follows:

alle Entries of level 1 and 2 and the selected entries on level 3 (listbox1)

Listbox2 has the ids of all entries

When listbox1 is selected, the actions do

save the selection in the variable

select listbox level to levels 1 and 2

select the possibles in listbox2

toggle the entries from the variable

in sql I would use a union all on the selected entries and the entries with level 1 and 2,

how can that be achieved in 1 expression?

BTW: the actions are running in the right order, but the value in the variable is not updated, as you explained

Regards

Klaus

stigchel
Partner - Master
Partner - Master

Hmm, difficult to understand without knowing your setup and data model, however I think I have thought of something you can try.

You can try creating an alternate state, then instead of storing the selection in a variable, make the selection in the alternate state (you can use triggers for this as well). Instead of the variable you can then later read the stored selection with a function that takes set analysis e.g. Only({MyAltState} MyField).

Not applicable
Author

Hi Piet,

that sounds genious. I used them before but did not think of them for this purpose.

I'll try that tomorrow and give you feedback.

Thanks and bye

Klaus