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

Announcements
ALERT: QlikView server communication interruptions following Microsoft Windows Domain Controller security updates
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Check if a Value in a field exists

Hi All,

I am writing a macro and I am trying to check to make sure the value exists in the field and if it does not I would like to write an error to my log file. I have tried declaring a variable and hoping that it would return True if it was able to be selected and False if not, but if my value exists it is selected and my variable returns False. My code is:

checkValue = Document.Fields(Attr1).Select(Attr2)

if checkValue is true then

....

Else

lg.WriteLine("Command could not be done because the value does not exist in the field.

Thanks

Labels (1)
4 Replies
Anonymous
Not applicable
Author

checkValue =ActiveDocument.Evaluate("count({$<Field={'Value'}>} Field)")

If checkValue>0, value exists

Not applicable
Author

Hi,

Tried to use your statement but it doesnt work for me.

if my field name is f and the value is v, what should this statement look like?

checkValue =ActiveDocument.Evaluate("count({$<Field={'Value'}>} Field)")


Thanks.

Anonymous
Not applicable
Author

It will be
checkValue =ActiveDocument.Evaluate("count({$<f={'v'}>} f)")

TKendrick20
Partner - Specialist
Partner - Specialist

This works great! Here's a snippit of what I'm doing in C#.

  • I added DISTINCT so that the output of 1 means the value exists in that field while an output of 0 means it does not exist
  • I added brackets "[]" around the field name so it will work with field names containing spaces and return 0 if the field name is empty

string countString = @"COUNT(DISTINCT{$<[" + fieldName + @"]={'" + value + @"'}>}[" + fieldName + @"])";


if (Int32.Parse(ReportControl.QVDoc.Evaluate(countString)) == 1)

{

     //whatever

}