2 Replies Latest reply on Jul 9, 2018 6:46 PM by David Hearn

    Getting elements when using AFSearchOperator.In does not work after software update


      Hi I have problem after software upgrade, now we are using newest one and I have problems with searching elements:


      var searchTokens = new List<AFSearchToken>
         new AFSearchToken(AFSearchFilter.TemplateName, AFSearchOperator.In, MY_TEMPLATE_NAMES.Split(','), db.Elements[BUILDING].GetPath()),
         new AFSearchToken(AFSearchFilter.Name, AFSearchOperator.Equal, "*Sensor")
      var search = new AFElementSearch(db, "name", searchTokens);


      i worked correctly, now I have following error message:


      Unexpected SQL Exception number 20111 with message: 'Invalid comparison operator 'In' for search criteria 'TemplateName'.'.\r\nUse Event Viewer to see the PI AF Server log file for more information.


      Could you tell me why now i cannot to use AFSearchOperator.In in my queries?

        • Re: Getting elements when using AFSearchOperator.In does not work after software update
          Rick Davin

          Hello Tomasz,


          Thanks for posting your problem here at PI Developers Club.  I think you must have changed something in your code, or perhaps you are remembering it differently, but the fact is that TemplateName does not nor has not support the IN search operator.


          Here is what the Search Overview shows for PI AF 2018 (AF SDK 2.10)


          2018-07-06 13_12_18-Window.png

          For it to support the IN operator, I would expect something to show like:


          2018-07-06 13_13_28-Window.png

          Okay, so the very latest release does not support the EqualOrInOperator for TemplateName.  What about the previous release, PI AF 2017 R2 (AF SDK 2.9.5)?  Search Overview shows:


          2018-07-06 13_15_21-Window.png


          Clearly this shows that for TemplateName, you cannot and could not have used the IN operator.  You may use the IN operator on Element in older versions, and now ID with 2.10.  There is a blog on coding tips with the IN operator that you may find helpful, although that is geared more towards filtering on attribute values.  And the Search Overview page is always a great bookmarked page.


          Even if TemplateName supported the IN operator, your code would not work because your path is incorrect.  The snippet db.Elements[BUILDING].GetPath() returns a path to one element down the path db.Elements, which could not be the same path as element templates down the path of db.ElementTemplates.


          Finally, not that there is any indication with what you've shown, but a given search capability will only allowed by the minimum of AF Server versus AF Client versions.  If your client is AF SDK 2.10, but the server is 2.9.5, then your search will be a 2.9.5 search.

          2 of 2 people found this helpful
          • Re: Getting elements when using AFSearchOperator.In does not work after software update
            David Hearn

            There was an issue fixed where the server did not report an error if it did not support an operator and would just ignore that part of the query. That is probably what you were seeing and did not realize that it was being ignored by the search.

            1 of 1 people found this helpful