GetDossierDocuments function |
This example searches the vault for a given property value and returns the documents with that value as an array.
' Return an array of documents belonging to the dossier Public Function GetDossierDocuments(ByRef DossierNumber As Object) As Object On Error GoTo leave Dim result As Object Dim sq As AMSearchQuery Dim pf As AMPropertyFilter Dim tv As IAMTableView Dim psCustom As AMPropertySet psCustom = m_DocumentRepository.Environment.PropertySets("Custom") sq = m_DocumentRepository.NewSearchQuery pf = sq.NewPropertyFilter pf.Property = psCustom.GetPropertyDefWithName("DossierNumber") pf.Operator = OP_EQUALS pf.value = DossierNumber tv = m_DocumentRepository.ExecuteQuery(sq, psCustom) result = tv.GetMultipleRowColumns(0, -1) tv = Nothing sq = Nothing pf = Nothing psCustom = Nothing ' Succeeded GetDossierDocuments = result Exit Functionleave: ' No MsgBox because this code may run on the server GetDossierDocuments = Empty End Function
' Return an array of documents belonging to the dossier Public Function QueryDocuments(ByVal dr As BCRepository, ByRef PropName As String, ByRef PropVal As Object) As Array Try Using psCustom As BCPropertySet = dr.Environment.PropertySets("Custom") Using sq As BCSearchQuery = dr.NewSearchQuery Using pf As BCPropertyFilter = sq.NewPropertyFilter pf.Property = psCustom.GetPropertyDefWithName(PropName) pf.Operator = OperatorKind.OP_EQUALS pf.Value = PropVal Using tv As BCReadOnlyCollection(Of BCDocument) = dr.ExecuteQuery(sq, psCustom.PropertyDefs) ' Succeeded QueryDocuments = tv.GetMultipleRowColumns(0, -1) End Using ' tv End Using ' pf End Using ' sq End Using 'psCustom Catch QueryDocuments = Nothing End Try End Function
In this example, Using statements are not obligatory because all of the objects will be released automatically when the transaction is committed or revoked. They are used here to shorten the lifetime of the objects to the absolute minimum.