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

Workflow Automatic Trigger causing infinite loop - workaround

Former Member
Former Member
Hello

I am trying to create a workflow that has a loop in it using Automatic Triggers. At the moment I have the object in State A with an Automatic Trigger from A to B. I would like to have an Automatic Trigger from B back to A. I know this idea is risky and causes an error message from M-Files: The automatic state transitions of this workflow can lead to an infinite automatic loop.

Would the easiest way around this be to use an Event Handler to move the object to the required workflow state (B)?

And if so, would the AfterSetProperties be the handler to use? The Automatic Trigger is carried out by the server so I'm guessing the object isn't checked out and so the AfterCheckInChanges handler wouldn't fire?

Does anyone have any advice on how to do something like this?
Parents
  • Dear LachlanMcCleary,

    I had recently similar issue. Here is response I got from M-files support:


    M-Files workflows does not allow infinite loop for performance reasons.

    In your use case, you have possible infinite loop between the states 3. and 4. as both of the state transitions "3. => 4." and "4. => 3." are automatic state transitions.

    If you are sure that infinite loop will not cause performance issues in your use case, scripting can be used to bypass infinite loop restriction.

    E.g. create an additional state between states 3. and 4. Screenshot attached.

    Add action script to to new "Additional state" to change to workflow back to state 3.

    E.g.



    ' *********************************

    Option Explicit

    Dim ApprovalState : ApprovalState = 151 ' Workflow State ID, check from Workflow States value list
    Dim oPropVal: Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
    oPropVal.PropertyDef = 39 ' Workflow states build-in property
    oPropVal.TypedValue.SetValue MFDatatypeLookup, ApprovalState
    Vault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal





    It is also possible to create trasition from your workflow state to "(0 no state)". In transition script you can make transition to go desired state by specifying NextStateID

    So I ended up creating transition from state B to state (0 no state) and specified similar trigger code:

    CONST STATE_A_ID = 103
    CONST CONDITION_PD = 1234

    dim StateCondition_PV: set StateCondition_PV = SearchForProperty(CONDITION_PD)

    'Some condition to trigger the state change.
    if StateCondition_PV.value.IsNull() then
    NextStateID = STATE_A_ID
    AllowStateTransition = true
    end if
Reply
  • Dear LachlanMcCleary,

    I had recently similar issue. Here is response I got from M-files support:


    M-Files workflows does not allow infinite loop for performance reasons.

    In your use case, you have possible infinite loop between the states 3. and 4. as both of the state transitions "3. => 4." and "4. => 3." are automatic state transitions.

    If you are sure that infinite loop will not cause performance issues in your use case, scripting can be used to bypass infinite loop restriction.

    E.g. create an additional state between states 3. and 4. Screenshot attached.

    Add action script to to new "Additional state" to change to workflow back to state 3.

    E.g.



    ' *********************************

    Option Explicit

    Dim ApprovalState : ApprovalState = 151 ' Workflow State ID, check from Workflow States value list
    Dim oPropVal: Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
    oPropVal.PropertyDef = 39 ' Workflow states build-in property
    oPropVal.TypedValue.SetValue MFDatatypeLookup, ApprovalState
    Vault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal





    It is also possible to create trasition from your workflow state to "(0 no state)". In transition script you can make transition to go desired state by specifying NextStateID

    So I ended up creating transition from state B to state (0 no state) and specified similar trigger code:

    CONST STATE_A_ID = 103
    CONST CONDITION_PD = 1234

    dim StateCondition_PV: set StateCondition_PV = SearchForProperty(CONDITION_PD)

    'Some condition to trigger the state change.
    if StateCondition_PV.value.IsNull() then
    NextStateID = STATE_A_ID
    AllowStateTransition = true
    end if
Children
No Data