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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Validating the incoming value in the Variable using Macro

Cust variable - I have defined in the Select in field OnOpen has action

Sub Customer
set CustomernoVar = ActiveDocument.Variables("Cust")
vCustomerNo = CustomernoVar.GetContent.String
msgbox(vCustomerNo)

if vCustomerNo = ActiveDocument.Fields("Customer_No").getPossibleValues then
  msgbox(" Valid Customer")
   ActiveDocument.Fields("Customer_No").Select(vCustomerNo)
 
  else
   msgbox("The customer is not valid")
  
end if

End sub

"Customer_No" is the data field in qlikview datamodel.

I have to check the incoming variable value is valid customer or not in the field "Customer_No".

It is not working- if I provide invalid value for the Cust variable - it is not suppose to display anything. Please help on this issue.

Advance Thanks for your help

3 Replies
m_woolf
Master II
Master II

Here is example code from the API Guide that shows how to loop through each possible value in a field.

You will need to compare vCustomerNo with each possible value and set a flag if you find a match.

set val=ActiveDocument.Fields("Month").GetPossibleValues

for i=0 to val.Count-1

    msgbox(val.Item(i).Text)

next

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Let me suggest a non-macro way to accomplish the objective. Assume the Fieldname is "Customer" and the variable name if "vCustomer".

1. Create a bookmark using the search expression:

=Customer='$(vCustomer)'

2. Create an alert that applies the bookmark and uses for condition:

=GetSelectedCount(Customer)=1

3. Assign an OnOpen action to apply the bookmark if you want the selection made.

Example attached.

-Rob

http://robwunderlich.com

Not applicable
Author

Hi Rob,

Thanks for the quick solution.

It is not going to work for my case.

Cust is always carry some values -I would like to verify the incoming Cus t values are available in the Customer_No field or not.If Cust has value which is not available in Customer_No - I don't need to show the report.

Advance thanks for your help.