Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Set value of expression to a variable, not the expression itself?

I am trying to use an action of a button (due to not knowing or really understanding VB, and the fact that macros do not work in webview)  to set getfeildselections() to a variable. I want the VALUE of the current selection saved, and not the formula for getfieldselections()

I have the button click action as set variable intercompany to getcurrentselection(custid)

When I click the button then check the variable screen, the variable intercompany says:getcurrentselection(custid)

Since the variable is set to the expression getcurrentselection(custid) and not the value of getcurrentselection(custid) it is changing the variable based on the selection instead of leaving it set to the selection on button click.

How can I get this to set the value of the expression, and not the expression itself?

1 Solution

Accepted Solutions
jykang0638
New Contributor III

Re: Set value of expression to a variable, not the expression itself?

I have tested the below and it is working.
You need two variables.
Let use vSelectedRecord for recording and vSpare for checking field selection.

In button actions - Add - External - Set variable

Variavle: vSpare, Value: =if(vSpare, 0, 1)

In Document Properties - Triggers - Variable Event Triggers
Select 'vSpare' as variable, then add two events - Select Excluded and Select Possible in the OnInput event.
And then add Set Variable action like the below in the OnChange event.
Variavle: vSelectedRecord, Value: =getFieldSelections(custid,',',100)

I hope it helps you.

11 Replies
jykang0638
New Contributor III

Re: Set value of expression to a variable, not the expression itself?

Hi,


See the variable settings and button actions on the attached sample qvw.
I hope it helps you.

Not applicable

Re: Set value of expression to a variable, not the expression itself?

I am on personal edition so I can not open your sample.

jagannalla
Valued Contributor III

Re: Set value of expression to a variable, not the expression itself?

Hello,

In button action -> Add -> External -> Set variable

Now in varaible textbox give your variablename & in value keep this code...

=GetFieldSelections(custid,',',100)

- Then the variable holds the 100 selections of listbox. If you don't give the size then by default the GetFieldSelections method allows you to select only 6 selected values.

Not applicable

Re: Set value of expression to a variable, not the expression itself?

I already have the variable set, my issue is that it is being set with the expression.

variable='GetFieldSelections(custid,',',100)'

when I want the results of the above:

variable='Not Cust1,Cust2,Cust3'

How it currently is, the variable is changing with the selection, where I want it to record the actual selected/not selected fields at the time of button click.

Edit:

Never mind, I see that when adding the = sign before, it is records the values. My test listbox that is showing me what the variable held was malfunctioning.

It is now recording the value of the selection, but now a new issue has apperared.

What the button is actually doing is it is selecting all internal Customer ID's (Internal company selling to another internal company). It is then selecting all excluded values.

this is where I am telling it to record the value of the excluded custid's to the variable. Now that it is working, I see that it is recording the value before the previous actions.

So when no selections are made and I click the button, it records an empty string.

If I click the button a second time, then it records the correct value.

Any ideas how to get around this?

jagannalla
Valued Contributor III

Re: Set value of expression to a variable, not the expression itself?

Ok then can you send what field and expression are you using in  the listbox...

For Eg:

In the listbox...Field is A and the expressiong is B like this if your listbox looks and data of this fields are:

Load * inline

[

A,B

x,y

w,z

];

then try in the variable value like this.

=if(wildmatch(GetFieldSelections(A,'',50),'*x*'),min({<A= {'*x*'}>}B),'')

jykang0638
New Contributor III

Re: Set value of expression to a variable, not the expression itself?

You have to set like the below:

leave the definition of your variable space

In button action - Add - External - Set variable
In Variavble Textbox, input your variable

IN Value Textbox, input =GetFieldSelections(custid)

Not applicable

Re: Set value of expression to a variable, not the expression itself?

I am not exactly sure what you are asking?

List box is set to an expression:

='$(intercompany)'

where intercompany is the variable being set by the button.

It just appears that the action Set variable is executing before the selections are actualy made.

I figured that according to the following image, it would do all the actions in order. Select (cust1|cust2|cust3). Then select excluded custid which changes the selection text to (Not cust1,cust2,cust3) which would then record this into the variable.

var.JPG

However it is not doing that, and when the qvw has no current selections, it is recording '' to the variable, and then setting the selections

jykang0638
New Contributor III

Re: Set value of expression to a variable, not the expression itself?

I have tested the below and it is working.
You need two variables.
Let use vSelectedRecord for recording and vSpare for checking field selection.

In button actions - Add - External - Set variable

Variavle: vSpare, Value: =if(vSpare, 0, 1)

In Document Properties - Triggers - Variable Event Triggers
Select 'vSpare' as variable, then add two events - Select Excluded and Select Possible in the OnInput event.
And then add Set Variable action like the below in the OnChange event.
Variavle: vSelectedRecord, Value: =getFieldSelections(custid,',',100)

I hope it helps you.

Not applicable

Re: Set value of expression to a variable, not the expression itself?

That works perfectly thank you everyone for your help.

Community Browser