Search
Welcome to M-Files Empower – our new support experience. We'd love to hear what you think!Give feedback
Home/Support and troubleshooting/Examples and how to

Automatic workflow state transition when document is changed

Last updated on 30 September 2020

Admin
Workflow

Overview

In some use workflow state automatic change may be wanted when document in workflow is changed and new version of document is created.
This can be done with script set in workflow state transition.

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

Solution

Let's assume the following workflow:


Setting the following script to state transition between Approved state and Draft states makes the workflow state change when new version of object is created (for example when document or it's metadata changes).
Option Explicit

' Moves object back to Draft state if approved object data has been changed.
Dim iCurrentStateID
iCurrentStateID = PropertyValues.SearchForProperty(39).TypedValue.GetLookupID
          
' Double-checks that older versions exist on the server
Dim ObjectVersions
Set ObjectVersions = Vault.ObjectOperations.GetHistory(ObjVer.ObjID)
If ObjectVersions.Count > 1 Then

    Dim ObjVerPreviousVersion
    Set ObjVerPreviousVersion = ObjectVersions.Item(2).ObjVer

    ' Get the workflow state of the previous version
    Dim iPreviousStateID
    iPreviousStateID = Vault.ObjectPropertyOperations.GetProperty(ObjVerPreviousVersion, 39).TypedValue.GetLookupID

           If iCurrentStateID = iPreviousStateID Then
                      AllowStateTransition = True
           End If
End If

Location for the script.

 

Still need help?

On this page