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

Search Multi Property by alias to get their ID

Hi all,

I am trying to set (flag) a property (called attached) within object class to yes (true). I do have a vbscript that works (within workflow state) but only for single properties list. I don't know how to make it work for MULTI properties list. Is there a way i can loop between all individual objects by Alias on the list (that i have added on the form) and set their attached property to true?


option explicit

'Define variables
Dim titleTypedValue
Dim oPropVal: Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
Dim oProp: Set oProp = vault.PropertyDefOperations
Dim oPropValsCurrent: Set oPropValsCurrent = CreateObject("MFilesAPI.PropertyValues")
Dim IsAttached
Dim Ref
Dim Prop

'Get ID of Property
Set Ref = SearchForObject("Milestone", 1)

'Call "ATTACHTED" property and get latest version of property
set IsAttached = vault.ObjectPropertyOperations.GetProperties (Ref.ObjVer, true)

'Set "ATTACHTED" Property value to true (Yes)
oPropVal.PropertyDef = oProp.GetPropertyDefIDByAlias("Attached")

oPropVal.TypedValue.SetValue MFDatatypeBoolean, true
oPropValsCurrent.Add -1, oPropVal

'Apply the new properties value
Vault.ObjectPropertyOperations.SetProperties Ref.ObjVer, oPropValsCurrent


'********************************************************************************************************************
'Search For Object method
function SearchForObject(PropertyID, Index)

Dim oPropertyValsSearch: set oPropertyValsSearch = vault.ObjectPropertyOperations.GetProperties (Objver, true)
Dim EmpName
Dim titleProperty
titleProperty = 1055

EmpName = oPropertyValsSearch.SearchForPropertyByAlias(vault, PropertyID , true).Value.DisplayValue


' Find the title property of the current object.
Dim titleSearch
Set titleSearch = CreateObject("MFilesAPI.SearchCondition")
Dim titleExpression
Set titleExpression = CreateObject("MFilesAPI.Expression")
titleExpression.SetPropertyValueExpression titleproperty, 0, Nothing

Dim titleTypedValue
Set titleTypedValue = CreateObject("MFilesAPI.TypedValue")
titleTypedValue.SetValue MFDatatypeText ,EmpName
titleSearch.Set titleExpression, MFConditiontypeEqual, titleTypedValue

Dim SearchResults
Set SearchResults = Vault.ObjectSearchOperations.SearchForObjectsByCondition(titleSearch, false)

Dim oObjID: set oObjID = SearchResults.Item(Index)

set SearchForObject = oObjID

end function
  • To make the question more simpler, how can i use SearchForPropertyByAlias(vault, PropertyID , true) on a property list (from list, MULTI)? Or there another way to get object id for each name in a property list?
  • Hi,
    Assuming that your workflow is on one object and you are trying to set a property on other objects that have been selected via a multi select property on the current object, right?
    If so, I would simply get the list of objects as lookups and then loop through each of them. I did something similar in a case not long ago. You should be able to adapt my approach to your situation.
    Dim iOTChild : iOTChild = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("OT.Child")
    Dim iPDSiblings : iPDSiblings = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.Children")
    Dim oSibling : set oSibling = CreateObject("MFilesAPI.Lookup")
    Dim oSiblings : set oSiblings = PropertyValues.SearchForProperty(iPDSiblings).TypedValue.GetValueAsLookups()
    Dim oObjVer, oObjVerProps
    Dim oObjID: set oObjID = CreateObject("MFilesAPI.ObjID")
    For Each oSibling in oSiblings
    oObjID.SetIDs iOTChild, oSibling.Item
    set oObjVer = vault.ObjectOperations.GetLatestObjVer(oObjID,False,True)
    set oObjVerProps = vault.ObjectOperations.GetObjectVersionAndProperties(oObjVer, True)
    'Insert your code to set the flag property here.


    Next
  • Yes correct, my workflows is on object called "contract", the other object type is Milestone, multi property is Milestones" and the property within his class that i am trying to set is to Yes is "Attachted_Milestone". I've done some testing with your code however i was unable to make it work, I believe I might be missing something. Since I'm getting "Unknown property definition "-1".
    that is caused by this Line: Vault.ObjectPropertyOperations.SetProperties oObjVer, oPropValsCurrent

    Any idea what I am doing wrong?

    My code:

    Dim iOTChild : iOTChild = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("Milestone") 'The other object type
    Dim iPDSiblings : iPDSiblings = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("Milestones") 'The other object type multi property
    Dim oSibling : set oSibling = CreateObject("MFilesAPI.Lookup")
    Dim oSiblings : set oSiblings = PropertyValues.SearchForProperty(iPDSiblings).TypedValue.GetValueAsLookups()
    Dim oObjVer, oObjVerProps
    Dim oObjID: set oObjID = CreateObject("MFilesAPI.ObjID")

    'Added these three variables
    Dim IsAttached
    Dim oPropVal: Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
    Dim oPropValsCurrent: Set oPropValsCurrent = CreateObject("MFilesAPI.PropertyValues")

    For Each oSibling in oSiblings
    oObjID.SetIDs iOTChild, oSibling.Item

    set oObjVer = vault.ObjectOperations.GetLatestObjVer(oObjID,False,True)
    set oObjVerProps = vault.ObjectOperations.GetObjectVersionAndProperties(oObjVer, True)
    'Insert your code to set the flag property here.

    'Added my code for flaging the boolean property
    'Set "ATTACHTED MILESTONE" Property value to true (Yes)
    oPropVal.PropertyDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("Attached_Milestone")
    oPropVal.TypedValue.SetValue MFDatatypeBoolean, true
    oPropValsCurrent.Add -1, oPropVal

    'Apply the new properties value
    Vault.ObjectPropertyOperations.SetProperties oObjVer, oPropValsCurrent

    Next
  • Three comments:
    1) You are using a fixed value (True) on all the siblings, so rather than setting the oPropVal in each iteration you should set it once before the iteration starts. This will save server time but has nothing to do with your error.
    2) You are only setting one property, no need to use the SetProperties method. Use SetProperty in stead. That way you can also skip the use of oPropValsCurrent
    3) You do not use oObjVerProps - skip that line as well.
    No guarantees but this might do it:
    Dim iOTChild : iOTChild = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("Milestone") 'The other object type
    Dim iPDSiblings : iPDSiblings = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("Milestones") 'The other object type multi property
    Dim oSibling : set oSibling = CreateObject("MFilesAPI.Lookup")
    Dim oSiblings : set oSiblings = PropertyValues.SearchForProperty(iPDSiblings).TypedValue.GetValueAsLookups()
    Dim oObjVer, oObjVerProps
    Dim oObjID: set oObjID = CreateObject("MFilesAPI.ObjID")
    Dim oPropVal: Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
    oPropVal.PropertyDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("Attached_Milestone")
    oPropVal.TypedValue.SetValue MFDatatypeBoolean, true

    For Each oSibling in oSiblings
    oObjID.SetIDs iOTChild, oSibling.Item
    set oObjVer = vault.ObjectOperations.GetLatestObjVer(oObjID,False,True)
    'Apply the new properties value
    Vault.ObjectPropertyOperations.SetProperty oObjVer, oPropVal
    Next
  • Almost there, i can feel it :P I tested the script as you sent me and i got this error: "The object is not checked out". Caused by this line:
    Vault.ObjectPropertyOperations.SetProperty oObjVer, oPropVal


    Knowing that the object must be checked out, I tried adding CheckOut and CheckIn functions. The code turned like this:

    Dim iOTChild : iOTChild = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("Milestone") 'The other object type
    Dim iPDSiblings : iPDSiblings = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("Milestones") 'The other object type multi property
    Dim oSibling : set oSibling = CreateObject("MFilesAPI.Lookup")
    Dim oSiblings : set oSiblings = PropertyValues.SearchForProperty(iPDSiblings).TypedValue.GetValueAsLookups()
    Dim oObjVer, oObjVerProps
    Dim oObjID: set oObjID = CreateObject("MFilesAPI.ObjID")
    Dim oPropVal: Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
    oPropVal.PropertyDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("Attached_Milestone")
    oPropVal.TypedValue.SetValue MFDatatypeBoolean, true
    'Added variable
    Dim CheckedOutObjeactVersion

    For Each oSibling in oSiblings
    oObjID.SetIDs iOTChild, oSibling.Item
    set oObjVer = vault.ObjectOperations.GetLatestObjVer(oObjID,False,True)

    'Added Check Out
    CheckedOutObjeactVersion = vault.ObjectOperations.CheckOut(oObjID)

    Vault.ObjectPropertyOperations.SetProperty CheckedOutObjeactVersion.ObjVer, oPropVal

    'Added Check In
    vault.ObjectOperations.CheckIn(CheckedOutObjeactVersion.ObjVer)
    Next


    I tested the loop and it's giving me the correct object ID.

    However I get another error "Object doesn't support this property or method" at line:
    CheckedOutObjeactVersion = vault.ObjectOperations.CheckOut(oObjID)


    I tried some other declaration alternatives however I'm still stuck getting this error.

    Do you know any way to break free out of this one?
  • Could be as simple as adding a "set" in front of the line.
    set CheckedOutObjeactVersion = vault.ObjectOperations.CheckOut(oObjID)
  • Well that was too good to be true. It fixed that line but now shows error: Unknown property definition "-1" on this line:

    Vault.ObjectPropertyOperations.SetProperty CheckedOutObjeactVersion.ObjVer, oPropVal

    Maybe i am not using the objver correctly?

  • Make sure the line
    oPropVal.PropertyDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("Attached_Milestone")
    produces the correct result. There could be typo in the Alias or elsewhere.
  • Just a quick note to say that I agree with Karl at Bright Ideas: the issue (now) is that the property isn't correctly resolved.

    The "GetPropertyIDByAlias" method returns -1 if it can't resolve the alias to an ID for some reason. Typically this is because the alias you've given it ("Attached_Milestone") is incorrect (not on the property, mistyped, etc.). It can also be if multiple property definitions have the same alias.

    You could debug this value by throwing an error:

    Err.Raise MFScriptCancel, Vault.PropertyDefOperations.GetPropertyDefIDByAlias("Attached_Milestone")


    Alternatively you could hard-code the ID here for a moment, just to prove that it's this line which is failing:

    oPropVal.PropertyDef = 1024


    Regards,

    Craig.

  • Make sure the line
    oPropVal.PropertyDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("Attached_Milestone")
    produces the correct result. There could be typo in the Alias or elsewhere.

    Well I guess I was too tired yesterday that I mistyped the alias on the boolean property. Many many thanks for you guidance, finally got it to work.

    Just a quick note to say that I agree with Karl at Bright Ideas: the issue (now) is that the property isn't correctly resolved.

    The "GetPropertyIDByAlias" method returns -1 if it can't resolve the alias to an ID for some reason. Typically this is because the alias you've given it ("Attached_Milestone") is incorrect (not on the property, mistyped, etc.). It can also be if multiple property definitions have the same alias.

    You could debug this value by throwing an error:

    Err.Raise MFScriptCancel, Vault.PropertyDefOperations.GetPropertyDefIDByAlias("Attached_Milestone")


    Alternatively you could hard-code the ID here for a moment, just to prove that it's this line which is failing:

    oPropVal.PropertyDef = 1024


    Regards,

    Craig.


    Craig, thanks for your explaining the problem and debug tips.


    Here the final code for anyone who may need it:

    'Declare required variables
    Dim iOTChild : iOTChild = vault.ObjectTypeOperations.GetObjectTypeIDByAlias("Milestone") 'Object type
    Dim iPDSiblings : iPDSiblings = vault.PropertyDefOperations.GetPropertyDefIDByAlias("Milestones") 'Property (Multi, From list)
    Dim oSibling : set oSibling = CreateObject("MFilesAPI.Lookup")
    Dim oSiblings : set oSiblings = PropertyValues.SearchForProperty(iPDSiblings).TypedValue.GetValueAsLookups()
    Dim oObjID: set oObjID = CreateObject("MFilesAPI.ObjID")
    Dim oPropVal: Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
    Dim CheckedOutObjeactVersion
    'Get property
    oPropVal.PropertyDef = vault.PropertyDefOperations.GetPropertyDefIDByAlias("Attachted_Milestone")
    'Sets the value of a typed value to True (Yes)
    oPropVal.TypedValue.SetValue MFDatatypeBoolean, true

    'Loop thru each milestone
    For Each oSibling in oSiblings
    oObjID.SetIDs iOTChild, oSibling.Item

    'Checks out the Milestone object
    set CheckedOutObjeactVersion = vault.ObjectOperations.CheckOut(oObjID)

    'Sets the specified property value (Object must be checked out first).
    vault.ObjectPropertyOperations.SetProperty CheckedOutObjeactVersion.ObjVer, oPropVal

    'Checks in the Milestone object back again.
    vault.ObjectOperations.CheckIn(CheckedOutObjeactVersion.ObjVer)
    Next