I am trying to use AFElementSearch in the AF SDK and I used the Search feature from the PI System Explore to create my query string, but I am getting a "Type required" error at runtime. Below are the details. Any help would be appreciated.
Here is my search from PI System Explorer
Here is the source code. The AFDB object has a valid AF database object defined. I have commented out some of the original code and hard coded the query string just for testing purposes.
'*********************************************************************
'* Function Name.: FindElementsByCategory
'* Written By....: Bryan Sower
'* Written On....: 01-Dec-2024
'* Purpose.......: This will return a collection of AFElement objects
'* which have the defined category assigned. If the
'* objParentElement is defined it will limit the search
'* to only child elements.
'*********************************************************************
'* Variables.....: CategoryName - Category to find objects for
'* objParentElement - AFElement object for parent element
'* CacheTimeout - Timeout for cache
'* Return - IEnumerable(Of AFElement)
'*********************************************************************
'* NOTES:
' https://docs.aveva.com/bundle/af-sdk/page/html/search-example.htm '** Use This One **
'*********************************************************************
'* MODIFICATIONS
'*********************************************************************
'* Rev. Date Initials Description
'* ---- ------------------- -------- ---------------------------------
'* 0001
'*********************************************************************
Public Function FindElementsByCategory(ByVal CategoryName As String, Optional ByRef objParentElement As AFElement = Nothing) As IEnumerable(Of AFElement)
Dim RtnName As String = "FindElementsByCategory"
Dim QryStr As String = String.Format("Category:'{0}'", CategoryName)
Dim ElmtQry As AFElementSearch = Nothing
Dim SearchElmts As IEnumerable(Of AFElement) = Nothing
'If (Not objParentElement Is Nothing) Then
' QryStr = String.Format("Parent:'{0}' AllDescendants:true Category:'{1}'", objParentElement.GetPath(), CategoryName)
'End If
'LogMsgInfo(3, String.Format("Searching for elements using query string of {0}", QryStr), RtnName)
QryStr = "Category:'Edict:ARSrxr_PhaseTimes'"
ElmtQry = New AFElementSearch(AFDB, RtnName, QryStr)
'ElmtQry.CacheTimeout = TimeSpan.FromMinutes(10)
SearchElmts = ElmtQry.FindObjects()
LogMsgInfo(3, String.Format("Elements found = {0}", SearchElmts.Count), RtnName)
Return (SearchElmts)
End Function
Here is a screen shot of the error: