Hi, I am trying to write VBScript to use as pre-condition on a workflow, to validate that a user has permission to perform a task
The test is: Current user is listed on the Project object as a Project User
The Project has a list of 'Project Users', which are Contact objects
The Contact objects have a property 'M-Files User' which links to their M-Files User Account (you may guess where the problem now lies)
My code so far will find the Project object, then loop through all the Project Users' Contact objects, and compare that to the CurrentUserID
' Verify the Created by user is a valid role on the Project selected
Dim pProjectObj : pProjectObj = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("H.Object.Project")
Dim pProject : pProject = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("H.Property.Project")
Dim pSupProjUser : pSupProjUser = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("H.Property.ProjectUser")
' 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 Users
Set objProps = Vault.ObjectOperations.GetObjectVersionAndProperties(objectVersion, true).Properties
If objProps.SearchForProperty(pSupProjUser).TypedValue.IsNULL() then
Err.Raise MFScriptCancel, "The selected Project has no listed Project Users"
End If
' Get all the Project Users from the selected Project
Dim pSPULookups : Set pSPULookups = objProps.SearchForProperty(pSupProjUser).TypedValue.GetValueAsLookups
' Compare the Current User -vs- the Project Users from the selected Project
Dim lookup : Set lookup = CreateObject("MFilesAPI.Lookup")
Dim IsValidCreate : IsValidCreate = 0
For Each lookup In pSPULookups
If lookup.Item = CurrentUserID Then IsValidCreate = 1
Next
' Display error if the comparison finds the current user isn't a Project User on the selected Project
If IsValidCreate = 0 Then
Err.Raise MFScriptCancel, "You are not listed as a Project User on the selected Project."
End If
However, the Contact IDs don't relate to the M-Files User Account IDs
So I need to read the M-Files User property from the Project Users, and then compare that to CurrentUserID
I think the middle section should be something like this, but it's not working and I've spent too long starting at it and can't think straight now, please help
For Each lookup In pSPULookups
Dim pMFilesUser : pMFilesUser = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("H.Property.MFilesUser")
Dim oMFilesUser : Set oMFilesUser = CreateObject("MFilesAPI.ObjVer")
oMFilesUser.Type = lookup.Type
oMFilesUser.ID = lookup.Item
Dim iMFilesUser : iMFilesUser = Vault.ObjectPropertyOperations.GetProperty(oMFilesUser, pMFilesUser).TypedValue.DisplayValue
If iMFilesUser = CurrentUserID Then IsValidCreate = 1