VbScript-Accessing the value of a property from results filtered by a certain condition

Hello,

I am developing a code that will run in mfiles with Vbscript. What I want to do here is to access the value of a feature in the result value returned to me as a result of the search conditions I sent. I wonder how can I do this?  I would be very happy if anyone with knowledge on the subject could help.

Thans for your help.

Parents
  • Assuming that your search is part of the script you will get a collection of ObjectSearchResults
    See some code example at the bottom of this page https://developer.m-files.com/APIs/COM-API/Reference/#MFilesAPI~VaultObjectSearchOperations.html

    Depending on what exactly it is you need, you may have to use Item or GetAsObjectVersions to drill down to the specific property needed.

  • When I tried to use Item, the code I wrote gave an error. Can you give me a short code example on how to use Item and how to get the property values ​​of the result?

    Thanks for your help.

  • HI,

    As Karl said it depends on the goal how you approach it.

    It would have been nice if you had posted the code or at least the fragment where you are having difficulty.

    Anyway here is some sample code how you can access the properties of a found object using item

    ' Create search Condisions
    Set oSCs = CreateObject("MFilesAPI.SearchConditions") 
    
    'Add Search Condition for filtering Class by ClassID
    Set oSCClass = CreateObject("MFilesAPI.SearchCondition") 
    oSCClass.ConditionType = MFConditionTypeEqual
    oSCClass.Expression.DataPropertyValuePropertyDef = 100 
    oSCClass.TypedValue.SetValue MFDatatypeLookup, iCLSalesDocument
    oSCs.Add -1, oSCClass
    
    'Add Search Condition for filtering Obejects(Documents) from Class SalesDocument by BuildIn property Name or Title 
    Set oSearchCondition = CreateObject("MFilesAPI.SearchCondition")
    oSearchCondition.ConditionType = MFConditionTypeEqual
    oSearchCondition.Expression.DataPropertyValuePropertyDef = 0
    oSearchCondition.TypedValue.SetValue MFDatatypeText, szPDInvoiceNumber
    oSCs.Add -1, oSearchCondition
    
    'Add Search Condition for exclude deleted objects
    Set oSearchNonDeleted = CreateObject("MFilesAPI.SearchCondition") 
    oSearchNonDeleted.ConditionType = MFConditionTypeEqual
    oSearchNonDeleted.Expression.DataStatusValueType = MFStatusTypeDeleted
    oSearchNonDeleted.TypedValue.SetValue MFDatatypeBoolean, False
    oSCs.Add -1, oSearchNonDeleted
    
    'Execute Search
    Set oSearchResults = Vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(oSCs,MFSearchFlagNone, False) 
    
    If oSearchResults.Count = 1 Then
    	Set oBindProperties = Vault.ObjectPropertyOperations.GetProperties(oSearchResults.Item(1).ObjVer, True)
    Else
    	'Something went wrong code
    End If

  • Option Explicit
    Dim ObjClass: ObjClass = Vault.ObjectOperations.GetObjectInfo(ObjVer,true).Class
    Const objType = objTypeId
    MsgBox
    Function MsgBox
    Const propDefStartTime =propertyId
    Const propDefEndTime = propertyId
    Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties( ObjVer, True )
    if( ObjVer.Type = objType) then

    Dim meetingStartTimeValue: meetingStartTimeValue = PropertyValues.SearchForProperty(propDefStartTime).TypedValue.DisplayValue
    Dim meetingEndTimeValue: meetingEndTimeValue = PropertyValues.SearchForProperty(propDefEndTime).TypedValue.DisplayValue


    Dim oSearch : Set oSearch = CreateObject("MFilesAPI.SearchCondition")
    Dim oSearchs : Set oSearchs = CreateObject("MFilesAPI.SearchConditions")

    oSearch.ConditionType = MFConditionTypeEqual
    oSearch.Expression.DataStatusValueType = MFStatusTypeObjectTypeID
    oSearch.TypedValue.SetValue MFDatatypeLookup, objType
    oSearchs.Add -1, oSearch

    oSearch.ConditionType = MFConditionTypeEqual
    oSearch.Expression.DataStatusValueType = MFStatusTypeDeleted
    oSearch.TypedValue.SetValue MFDatatypeBoolean, False
    oSearchs.Add -1, oSearch

    oSearch.ConditionType = MFConditionTypeEqual
    oSearch.Expression.DataPropertyValuePropertyDef = propDefStartTime
    oSearch.TypedValue.SetValue 6, meetingStartTimeValue
    oSearchs.Add -1, oSearch

    oSearch.ConditionType = MFConditionTypeEqual
    oSearch.Expression.DataPropertyValuePropertyDef = propDefEndTime
    oSearch.TypedValue.SetValue 6, meetingEndTimeValue
    oSearchs.Add -1, oSearch

    Dim oResults
    Set oResults = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oSearchs, MFSearchFlagNone, False)
    If oResults.Count > 0 Then
    Dim i : Dim oRes
    For i=1 To oResults.Count
    Set oRes = oResults.Item(i)
    If oRes.ObjVer.ID<>ObjVer.ID Then
    //Messages
    End if
    Next
    End if
    End if
    End Function

    The code I wrote with Vbscript is as above. If there is an object with the same range for the time values ​​entered in the newly created object as the time values ​​entered in the previously created objects, I want to prevent it from creating the new object. So I want to guarantee that it creates a single object in the same time zone.

    How can I write code that checks the clock property values ​​from the results obtained in the for loop and returns messages accordingly?

    Thanks for your helps.

Reply
  • Option Explicit
    Dim ObjClass: ObjClass = Vault.ObjectOperations.GetObjectInfo(ObjVer,true).Class
    Const objType = objTypeId
    MsgBox
    Function MsgBox
    Const propDefStartTime =propertyId
    Const propDefEndTime = propertyId
    Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties( ObjVer, True )
    if( ObjVer.Type = objType) then

    Dim meetingStartTimeValue: meetingStartTimeValue = PropertyValues.SearchForProperty(propDefStartTime).TypedValue.DisplayValue
    Dim meetingEndTimeValue: meetingEndTimeValue = PropertyValues.SearchForProperty(propDefEndTime).TypedValue.DisplayValue


    Dim oSearch : Set oSearch = CreateObject("MFilesAPI.SearchCondition")
    Dim oSearchs : Set oSearchs = CreateObject("MFilesAPI.SearchConditions")

    oSearch.ConditionType = MFConditionTypeEqual
    oSearch.Expression.DataStatusValueType = MFStatusTypeObjectTypeID
    oSearch.TypedValue.SetValue MFDatatypeLookup, objType
    oSearchs.Add -1, oSearch

    oSearch.ConditionType = MFConditionTypeEqual
    oSearch.Expression.DataStatusValueType = MFStatusTypeDeleted
    oSearch.TypedValue.SetValue MFDatatypeBoolean, False
    oSearchs.Add -1, oSearch

    oSearch.ConditionType = MFConditionTypeEqual
    oSearch.Expression.DataPropertyValuePropertyDef = propDefStartTime
    oSearch.TypedValue.SetValue 6, meetingStartTimeValue
    oSearchs.Add -1, oSearch

    oSearch.ConditionType = MFConditionTypeEqual
    oSearch.Expression.DataPropertyValuePropertyDef = propDefEndTime
    oSearch.TypedValue.SetValue 6, meetingEndTimeValue
    oSearchs.Add -1, oSearch

    Dim oResults
    Set oResults = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oSearchs, MFSearchFlagNone, False)
    If oResults.Count > 0 Then
    Dim i : Dim oRes
    For i=1 To oResults.Count
    Set oRes = oResults.Item(i)
    If oRes.ObjVer.ID<>ObjVer.ID Then
    //Messages
    End if
    Next
    End if
    End if
    End Function

    The code I wrote with Vbscript is as above. If there is an object with the same range for the time values ​​entered in the newly created object as the time values ​​entered in the previously created objects, I want to prevent it from creating the new object. So I want to guarantee that it creates a single object in the same time zone.

    How can I write code that checks the clock property values ​​from the results obtained in the for loop and returns messages accordingly?

    Thanks for your helps.

Children
No Data