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

How to avoid infinite automatic loop in workflow

Last updated on 28 February 2021

Admin
Workflow

 Overview

If you have automatic state transitions back and forth then M-Files sees that there is a possibility to create infinite loop and does not allow to save the workflow. You see an error message: "The automatic state transitions of this workflow can lead into an infinite automatic loop.". It doesn't check your settings further if that is really possible or not. 

Solution

You can avoid this with scripting and extra state.

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.
 

1. Create a new state between your automatic state transitions, e.g. between "State1" and "State2". Here in my example I use the name "Extra state" but you can of course use whatever name you want to for your new state. 

2. You can use the same automatic transition from "State1" to "Extra state" as you have now between "State1" and "State2".

3. Draw a regular state transition from "Extra state" to "State2"

4. Add script to "Extra state" action tab

 

-----------------

Option Explicit

 

Dim workflowState : workflowState = 151 ' State ID to move to, check the ID from Workflow states value list

Dim oPropVal: Set oPropVal = CreateObject("MFilesAPI.PropertyValue")

oPropVal.PropertyDef = 39 ' Workflow states

oPropVal.TypedValue.SetValue MFDatatypeLookup, workflowState

Vault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal

 

------------------------------

So the trick is to fool M-Files engine that there is no chain of automatic state transitions which could create an infinite loop - you should not get the error. But when the object moves to the state "Extra state", it is immediately moved to the correct state automatically by the script.

But please be careful, you can create an infinite loop this way.

The only thing you have to change in the script above is value 151 to correct one. You must check that in your Admin tool in "Value lists" from the built-in value list "States" (value list ID is 8). Open that value list and see the "Contents". Check what is the ID of your state "State2" and replace 151 in the script with that value.

 

Still need help?

On this page