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 State Transition by calculated date

Former Member
Former Member
Hi

I was wondering if it is possible to define a automatic state change on a workflow based on a date, that has been calculated using an object's date property.

Regards

Yaney
  • Yaney,

    You can certainly do this. For example, if you have a date property called Effective through in your agreements and you want to move the agreements from Approved state to Expired state automatically when the expiry date has passed, you can simply open up Approved state properties and define automatic state transition to expired state. See enclosed screenshot for details.

    Mika
  • Former Member
    Former Member
    Hi All,

    I want to do the a similar thing to what is described here, except instead of "Date" based, I want to have the state transition to occur based on time..

    Example:

    I am already Automatically setting the time property when a document is received (Property = Received Time = Now()")
    I want to move the document to a new workflow state called "Urgent" if the workflow isn't changed within 3 hours

    Is this possible?
    The only options the time property gives me is setting a fixed time.
    I cant find a way to do "change state if "received time + 3h"

    Thanks

    Steve

  • Steve,

    Triggers based on time are not supported out of the box in the M-Files notification system, so the best option would be creating a custom app that you would run with Windows Scheduler, say every 5 minutes and that would search for the objects where the workflow is not changed within 3 hours and then move them to another state.

    Mika
  • Former Member
    Former Member
    Hi All,

    I need to calculate time taken between the two states.
    Example. I have two states Start & End.
    I want to calculate time, i.e. when assigned person clicks on Start state, carries out the steps/task and once done clicks on End State.
    I want to know time taken by the assigned person to carry out the assigned task
  • You can calculate the difference between the timestamps (dates with time specified) using vb script function DateDiff, see www.w3schools.com/.../asp_ref_vbscript_functions.asp
    You have the timestamps in the Last modified property for each version. However, it would be a good idea to copy those timestamps into separate properties as a workflow action in each of the relevant states. The timestamp is probably not available at the time when the action script is run though. In stead you could just use system time Now to set the timestamp. Make sure you set the calculation order in the calculated field to make it work after the timestamp has been set.
    So, in Start State you create an action script that sets a timestamp for Start, and in End State you create an action script that sets a timestamp for End and add a property with a calculated value as the DateDiff between Start and End.
  • Have M-Files solved the requirement of trigger a state transition in time?, I was testing a script that calculate the difference in minutes to trigger the state but doesn't work, Response from Mika was on 2014.


    Option Explicit

    Const INTERVAL = 6 'every 6 minutes

    Dim dThisState : dThisState = PropertyValues.SearchForProperty( MFBuiltInPropertyDefStateEntered ).TypedValue.Value
    Dim dDeadLineTime : dDeadLineTime = Now()
    Dim tInterval, dThisStateUpdated

    ' Adapting the Time Zone (-3)
    dThisStateUpdated = DateAdd("h",-3, dThisState)

    ' Calculating the interval
    tInterval = DateDiff("n", dThisStateUpdated, dDeadLineTime)

    If tInterval = INTERVAL Then
    AllowStateTransition = true
    Else
    'Do nothing
    End If
  • Have used the script below to delay state transition i various situations. You can easily adapt it to trigger after e.g. 6 hours.
    Have used it in a combination of 2 workflow states where this script after a defined pause triggers a transition to the next state where another script in Workflow Actions sends the object back to the original state. Effectively the workflow repeats itself with the delay defined in this script plus some delay that comes from the interval set on the M-Files for how often the server checks whether transitions meet the criteria set in their configurations.
    'Make workflow pause x minutes before moving on
    'Will only work on new objects because it compares Created time to present time, consider using LastModified (21) if relevant.
    'Delay will be minimum the specified x minutes. Can be up to 60 + x minutes depending on when M-Files server checks the conditions.
    'Script to be placed in Transition Trigger
    '2019.07.04 Karl Lausten
    Option Explicit
    Dim dCreated : dCreated = PropertyValues.SearchForProperty(20).TypedValue.GetValueAsTimeStamp().UtcToLocalTime().GetValue()
    'Desired delay in minutes:
    Dim iDelay : iDelay = 5
    Dim dGoAhead : dGoAhead = DateAdd("n",iDelay,dCreated)
    'test time settings to verify the setup.
    'err.raise mfscriptcancel, "dCreated (UTC converted to local time):" & dCreated & ", dGoAhead: " & dGoAhead & ", now (local time):" & now
    if now > dGoAhead then
    AllowStateTransition = True
    end if
  • Thanks Brigth-ideas.dk, the last script I posted, works to control transitions if the interval is considered in hours, but does not work for minutes, the idea is to set escalations if the state transition have not been triggered in less of (by example) 20 minutes.

    but this one

    TypedValue.GetValueAsTimeStamp().UtcToLocalTime().GetValue()

    is a very useful tip to control the local time zone difference automatically.

    thanks a lot.