Getting objects using advanced query - SmartPlant Foundation - IM Update 44 - Customization & Programming - Hexagon

SmartPlant Foundation Customization

Language
English
Product
SmartPlant Foundation
Search by Category
Customization & Programming
SmartPlant Foundation / SDx Version
10

To retrieve data using more complex queries, you need to use the QueryRequest class. This class is in the SPF.Client.Administration namespace. The results are returned in an object of class QueryResult, which also in the SPF.Client.Administration namespace. The steps involved are as follows.

  • Create the QueryRequest.

  • Build the query using the various Add methods on the QueryRequest.

  • Execute the query using the ExecuteQuery method on the QueryRequest.

  • Iterate through the QueryResults.

There are several variants of the constructor, and the differences should be familiar to you by now after working with the variants of GetObjectsByName.

Public Sub New(ByVal pobjSession As SPFSession, ByVal pblnCountOnly As Boolean)

Public Sub New(ByVal pobjSession As SPFSession, ByVal pblnCountOnly As Boolean, ByVal pstrColumnSet As String)

Public Sub New(ByVal pobjSession As SPFSession, ByVal pblnCountOnly As Boolean, ByVal pstrColumnSet As String, ByVal pstrMethodUID As String, ByVal pblnRestrictedQuery As Boolean)

An example of creating a new QueryRequest is as follows.

Dim lobjQueryRequest As QueryRequest = New QueryRequest(Me.SPFSession, False)

To specify the query parameters, the Add methods on the QueryResult object should be used. One of the simplest is to specify an InterfaceDefUID that the object must have.

Public Sub AddQueryInterface(ByVal pstrInterfaceUID As String)

Here is an example of using this method.

lobjQueryRequest.AddQueryInterface("IPIDProcessVessel")

SHARED Tip You may call this method repeatedly to specify when there are multiple interfaces on the object.

Two other methods allow you to quickly add property value queries:

Public Sub AddQueryProperty(ByVal pstrPropertyDefUID As String, ByVal pstrValue As String)

Public Sub AddQueryProperty(ByVal pstrPropertyDefUID As String, ByVal pstrValue As String, ByVal pstrUOM As String)

Examples of their usage:

lobjQueryRequest.AddQueryProperty("Name", "*")

lobjQueryRequest.AddQueryProperty("Design_Temperature", "150.0", "C")

Three other variants allow you to specify comparison operators other than '=' or 'LIKE':

Public Sub AddQueryPropertyWithCriteria(ByVal pstrPropertyComparison As String)

Public Sub AddQueryPropertyWithCriteria(ByVal pstrInterfaceDef As String, ByVal pstrPropertyDef As String, ByVal pstrOperator As String, ByVal pstrValue As String)

Public Sub AddQueryPropertyWithCriteria(ByVal pstrPathDefn As String, ByVal pstrInterfaceDef As String, ByVal pstrPropertyDef As String, ByVal pstrOperator As String, ByVal pstrValue As String)

An example of using the above method could be to traverse from a document version up to the document revision, and then look at the Revision state property to ensure its value is current or working.

-SPFRevisionVersions~ISPFDocumentRevision~SPFRevState~=~e1CURRENT|e1WORKING

You can search for an object by OBID, UID, UID1, and UID2 using two methods, AddQueryProperty and AddQueryPropertyWithCriteria.

For example, you can search and return objects that are an exact match:

AddQueryProperty("UID", "123456")

AddQueryPropertyWithCriteria("IObject", "UID", "=", "123456")

Or you can use special properties and wildcard characters to refine the search:

AddQueryPropertyWithCriteria("IObject", "UID", "like", "*123456")

AddQueryPropertyWithCriteria("IObject", "UID", "like", "*123456*")