This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to build a SearchCondition on related property

How do I build a search condition on a related property using the API.
I have an object class RemitTo which has a property ParentVendor, which is a lookup from another object which has a property VendorCode.
I want to construct a search for RemitTo objects where the ParentVendor.VendorCode is equal to something.

I can get the ParentVendor lookup Property as follows:
           
' Create a search condition for the Parent Vendor.VendorCode
                oSearchCondition.ConditionType = MFConditionType.MFConditionTypeContains
                oSearchCondition.Expression.DataPropertyValuePropertyDef = oVault.PropertyDefOperations.GetPropertyDefIDByAlias(LSAliasPropertyDefIDParentVendor)
                oSearchCondition.TypedValue.SetValue(MFDataType.MFDatatypeText, "LAMI001")
                oSearchConditions.Add(-1, oSearchCondition)


But what I really want is as ParentVendor.VendorCode, see attached screenshot.
  • Hi Arnie

    Below is a code example to retrieve all objects where Project.Customer.Country = 1 (USA). This should work against the Sample vault and gives you an idea how to create indirect search conditions with M-Files API:


    ' Define Indirection Levels
    Dim oIndirectionLevels As New MFilesAPI.PropertyDefOrObjectTypes

    'Project
    Dim oIndirectProject As New MFilesAPI.PropertyDefOrObjectType
    oIndirectProject.PropertyDef = False
    oIndirectProject.ID = 101 ' Project Object Type
    Call oIndirectionLevels.Add(-1, oIndirectProject)

    ' Customer
    Dim oIndirectCustomer As New MFilesAPI.PropertyDefOrObjectType
    oIndirectCustomer.PropertyDef = False
    oIndirectCustomer.ID = 136 ' Customer Object Type
    Call oIndirectionLevels.Add(-1, oIndirectCustomer)

    ' Create the expression.
    Dim oExpression As New MFilesAPI.Expression
    oExpression.IndirectionLevels = oIndirectionLevels
    Call oExpression.SetTypedValueExpression(MFDatatypeLookup, 154, MFParentChildBehaviorNone, Nothing)

    Dim oSc As New MFilesAPI.SearchCondition

    oSc.Expression = oExpression
    oSc.ConditionType = MFConditionType.MFConditionTypeEqual
    Call oSc.TypedValue.SetValue(MFDataType.MFDatatypeLookup, 1) ' Country = USA.

    Dim oResults As MFilesAPI.ObjectSearchResults
    Set oResults = Vault.ObjectSearchOperations.SearchForObjectsByCondition(oSc, False)