Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello! I apologize if this is in the wrong place; scripting seemed the most appropriate.
I'm new to QlikView and am attempting to write a macro in v12.0.20400 where I need to check if a specific field has been selected or not. Having a msgbox is not my desired result, but a way for me to figure out the syntax of the condition. The field is Year and I have searched the community extensively, but nothing I've come across works. I'll provide examples of what I've tried below, but for confidentiality purposes, I cannot upload the QVW.
When the year is already selected, this below code returns the year. I suspect this is returning a string, but am not 100% sure. When the year is not selected, i.e. does not display in Current Selections, the macro fails with "Invalid procedure call or argument".
Set yearValue = ActiveDocument.Fields("Year").GetSelectedValues
If yearValue(0).Text = "" Then
msgbox("No year selected!")
Else
msgbox(yearValue(0).Text)
End If
From https://community.qlik.com/thread/86290, I should be able to use the field directly. I tried the following, but it too failed; this time with, "Wrong number of arguments or invalid property assignment: 'Year'". I tried without [] and "" instead and got the same result.
If IsNull([Year]) = -1 Then
msgbox("No year selected!")
Else
msgbox(yearValue(0).Text)
End If
From https://community.qlikview.com/thread/10952, I should be able to use the field directly. I tried the below code, but it failed as well; "Type mismatch: 'GetSelectedCount'. I've also tried without "", but received, "Wrong number of arguments or invalid property assignment: 'Year'".
If GetSelectedCount("Year") > 1 Then
msgbox("No year selected!")
Else
msgbox(yearValue(0).Text)
End If
From https://community.qlik.com/thread/164879, I tried the below and it too fails. Specifying Year without quotes returns, "Wrong number of arguments or invalid property assignment: 'Year'". Specifying Year with quotes returns, "Type mismatch: 'GetFieldSelections'".
If IsNull(GetFieldSelections("Year")) > -1
msgbox("No year selected!")
Else
msgbox(yearValue(0).Text)
End If
I've also tried IsEmpty with all of these with no luck. Does anyone know what I'm missing here?
Hi Michael
Maybe this
Set x = ActiveDocument.Fields("Year").GetSelectedValues
If x.count=0 Then
msgbox("No year selected!")
Else
msgbox(x.item(0).text)
End If
Regards
Pratyush
Hi Michael
Maybe this
Set x = ActiveDocument.Fields("Year").GetSelectedValues
If x.count=0 Then
msgbox("No year selected!")
Else
msgbox(x.item(0).text)
End If
Regards
Pratyush
Hi Michael,
Why a macro? Why not this expression in a textbox?
=if(GetSelectedCount(Year)=0,'No Year Selected')
Cheers
Andrew
A macro is required because I am automating the regression testing of a product utilizing QV and knowing which Year is selected determines the logic path.
Thank you Pratyush, that did the trick. Do you know how I could go about determining which properties are available for a given object and how to make the call to retrieve them?
Hi Michael
So you can write macro commands depending on what properties you want to call. There's nothing available at the go where you can set your own properties.
Regards
Pratyush
Hi Pratyush,
I do not know what you mean by set my own properties, but that does not sound like what I am asking. Is anyone aware of a resource providing which properties are available for various objects and how to call them?
Best,
Michael