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

Parents
  • 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

Reply
  • 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

Children
No Data