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

Fetch properties from a related object

Hi all, we have a Project object which has a property where we can tag the Project Approvers
We also have a Approval Task object, on which we have properties with which we can tag the related Project(s), as well as the related Project Approver(s)

We want to use VB Script in the Workflow's Pre-Conditions, to verify that the selected Project Approver on the Approval Task is correct - in that they are also tagged on the selected Project

(I know something like this could be done with filtering the properties by other properties, but there's a more complicated situation regarding that which means we need Pre-condition as a check)
I'm struggling to get this working, mainly I'm not sure how to pull the properties from the linked Project object to do my comparison

Many thanks

  • I guess you would have to identify the linked object by its ObjVer, use GetProperties from that ObjVer, and then use SearchForProperty to get the propertyvalue for the relevant property from that set of propertyvalues.

  • Yea, I think I've got the bulk of it working. --- see other reply what I got working 

    Many thanks

  • You are on the right track, you can clean up the first part a bit as well if you want:

    Dim Project_ObjVer : set Project_ObjVer = PropertyVals.SearchForProperty(pProject).TypedValue.GetValueAsLookup().GetAsObjVer()
    Set Project_ObjVer = vault.ObjectOperations.GetLatestObjVer(Project_ObjVer.ObjID, false, false)
    Dim Project_Properties : set Project_Properties =  Vault.ObjectOperations.GetObjectVersionAndProperties(Project_ObjVer, true).Properties

    From there you can do a validation to check if the approvers in your PropertyValues = the approvers in your  project_properties 

  • I tried to integrate your suggestion, it does look better.

    Many thanks


    But I think it is failing because the Project selection on the Approval Task object is actually a Multiselect property.
    (I prefer to use the built-in properties for objects when possible, and then use metadata card config to set them as 'Multi select as Single select')

    Here's my attempt with your code included: 

    ' Workflow "Update Status Code" > Workflow State "Open" > Preconditions 
    ' Verify the Project Approver selected is also a valid Project Approver on the Project selected
    
    Dim pProjectObj : pProjectObj = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("H.Object.Project")
    Dim pProject : pProject = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("H.Property.Project")
    Dim pApprover : pApprover = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("H.Property.ProjectApprover")
    
    ' Get selected Project Approver from current Approval Task
    Dim oApprover : oApprover = PropertyValues.SearchForProperty(pApprover).TypedValue.GetValueAsLookup.Item
    
    
    ' Get the selected Project 
    Dim Project_ObjVer : set Project_ObjVer = PropertyValues.SearchForProperty(pProject).TypedValue.GetValueAsLookup().GetAsObjVer()
    Set Project_ObjVer = vault.ObjectOperations.GetLatestObjVer(Project_ObjVer.ObjID, false, false)
    Dim Project_Properties : set Project_Properties =  Vault.ObjectOperations.GetObjectVersionAndProperties(Project_ObjVer, true).Properties
    
    	If Project_Properties.SearchForProperty(pApprover).TypedValue.IsNULL() then
    	    Err.Raise MFScriptCancel, "The selected Project has no listed Project Approvers"
    	End If
    
    ' Get all the Project Approvers from the selected Project
    Set Project_Properties = Vault.ObjectOperations.GetObjectVersionAndProperties(objectVersion, true).Properties
    Dim pPALookups : Set pPALookups = objProps.SearchForProperty(pApprover).TypedValue.GetValueAsLookups
    
    ' Compare the selected Project Approver on current Approval Task ObjVer -vs- the Project Approvers from the selected Project
    Dim PAlookup : Set PAlookup = CreateObject("MFilesAPI.Lookup")
    Dim IsPAValid : IsPAValid = 0
    
    For Each PAlookup In pPALookups
        If oApprover = PAlookup.Item Then IsPAValid = 1
    Next
    Err.Raise MFScriptCancel, IsPAValid
    ' Display error if the comparison finds the selected Project Approver isn't on the selected Project
    If IsPAValid = 0 Then
    	Err.Raise MFScriptCancel, "The selected Project Approver is not listed as such on the selected Project."
    End If

  • Here's what I got working, many thanks all

    ' Workflow "Update Status Code" > Workflow State "Open" > Preconditions 
    ' Verify the Project Approver selected is also a valid Project Approver on the Project selected
    
    Dim pProjectObj : pProjectObj = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("H.Object.Project")
    Dim pProject : pProject = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("H.Property.Project")
    Dim pApprover : pApprover = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("H.Property.ProjectApprover")
    
    ' Get selected Project Approver on current Approval Task
    Dim oApprover : oApprover = PropertyValues.SearchForProperty(pApprover).TypedValue.GetValueAsLookup.Item
    
    
    ' Get the selected Project 
    Set buCollection = PropertyValues.SearchForProperty(pProject).TypedValue.GetValueAsLookups
    Set bu = buCollection( 1 )
    Set objID = CreateObject("MFilesAPI.ObjID")
    objID.ID = bu.Item
    objID.Type = pProjectObj
    Set objectVersion = Vault.ObjectOperations.GetLatestObjVer( objID, false, false )
    
    	' Check the Project actually has any listed Project Approvers
    	Set objProps = Vault.ObjectOperations.GetObjectVersionAndProperties(objectVersion, true).Properties
    	If objProps.SearchForProperty(pApprover).TypedValue.IsNULL() then
    	    Err.Raise MFScriptCancel, "The selected Project has no listed Project Approvers"
    	End If
    
    ' Get all the Project Approvers from the selected Project
    Set objProps = Vault.ObjectOperations.GetObjectVersionAndProperties(objectVersion, true).Properties
    Dim pPALookups : Set pPALookups = objProps.SearchForProperty(pApprover).TypedValue.GetValueAsLookups
    
    ' Compare the selected Project Approver on current Approval Task ObjVer -vs- the Project Approvers from the selected Project
    Dim PAlookup : Set PAlookup = CreateObject("MFilesAPI.Lookup")
    Dim IsPAValid : IsPAValid = 0
    
    For Each PAlookup In pPALookups
        If oApprover = PAlookup.Item Then IsPAValid = 1
    Next
    
    ' Display error if the comparison finds the selected Project Approver isn't on the selected Project
    If IsPAValid = 0 Then
    	Err.Raise MFScriptCancel, "The selected Project Approver is not listed as such on the selected Project."
    End If