Home
About
Search
Welcome to M-Files Empower – our new support experience. We'd love to hear what you think!Give feedback
Home

Vbscript: check and prevent change of a property value

Last updated on 29 March 2022 · 2 min read

COM API

Overview

Please note that scripting is not part of standard support, and this is just an example script to show how to use the API. Be aware that all scripts are run at your own risk.

Sometimes there are needs to enforce that users cannot change for example a value list item to another. For example, a project's status cannot be set back to Draft once it has been set to In Progress.

While M-Files Workflows are by default a better way to handle the above (via controlling what status changes are possible) there may be some cases where workflows are already used for something else, and users need to have permission to edit said property.

 

Solution

The following is a small sample script for checking what the currently selected value is and what the previous value was, so essentially it prevents changing the value from 2 to 1 (lookup IDs).
Please note that this checks only the previous version, not the entire version history, and it uses hard coded property ID instead of aliases. With some enhancements it could also prevent clearing the value once it has been set.


If ObjVer.Version > 1  Then
    dim VLprop, currVal, prevVal
    VLprop = 1156
    currVal = Vault.ObjectPropertyOperations.GetProperty( ObjVer, VLprop).TypedValue.GetLookupID

    Dim oObjVerClone : Set oObjVerClone = ObjVer.Clone
    oObjVerClone.Version = ObjVer.Version - 1
    prevVal = Vault.ObjectPropertyOperations.GetProperty( oObjVerClone, VLprop).TypedValue.GetLookupID

    if currVal = 1 and prevVal = 2 Then
    Err.Raise MFScriptCancel, "You cannot go back to item 1"
    End if

End if
 

Still need help?

On this page