You are viewing limited content. For full access, please sign in.

Discussion

Discussion

SDK: Search which includes '<>' (not equals) doesn't properly handle empty fields

posted on March 2, 2022

The easiest way to explain this is through an example.

Here is the test data:

Folder Name: "One"
Metadata: RecID: "1111"; Status: "Open"

Folder Name: "Two"
Metadata: RecID: "1111"; Status: "Closed"

Folder Name: "Three"
Metadata: RecID: "1111"; Status: "" (never set)

These are the search strings and results:

Search #1:
{[]:[RecID]="1111"}&{LF:Name="*",Type="F"}

Search #1 Result:
    One
    Two
    Three

The above is a simple search and works as expected.

Search #2:
{[]:[RecID]="1111"}&{LF:Name="*",Type="F"}&{[]:[Status]<>"Closed"}

Search #2 Result:
    One

Notice that "Three" is missing, even though it meets the search criteria.  My assumption is that when the metadata field was never populated (either is null or doesn't exist, depending upon the internal structure) the search test fails and is treated as a false.  While this may make technical sense, it's not what a user would typically expect if they were just trying to filter out records with a 'Closed' status.

I did, however, come up with a workaround:

Search #3:
{[]:[RecID]="1111"}&{LF:Name="*",Type="F"}&({[]:[Status]<>"Closed"}|{[]:[Status]=""})

Search #3 Result:
    One
    Three

I'm posting this since I believe this behavior should be considered a bug in the search logic, as well as to hopefully save others some needless frustration if they run into the same issue.

 

0 0
replied on March 2, 2022 Show version history

Instead of using <> Not Equal, you should use the "- {= "Closed"}" to remove those that are "Closed"

({[]:[RecID]="1111"} & {LF:Name="*", Type="F"}) - {[]:[Status]="Closed"}

Any time a value is specified in the field, the search assumes to ignore empty values.  So your "{[]:[Status]<>"Closed"}" literally means Status field with any non-blank value not equal to "Closed".  This is by design and the easiest way to think of it is by how they get the {[]:[FieldName]="*"} to work for fields with any non blank value instead of anything or nothing.

Search field value = *

{[]:[RecID]="1111"} & {LF:Name="*", Type="F"} & {[]:[Status]="*"}

Results:
One
Two
2 0
replied on March 2, 2022

@Bert, thanks so much!  This is much cleaner than the workaround I had done. 

I had read through the search documentation, but missed this one, though now that I reread 'Search Operators' I see that it's there.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.