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 state precondidion setting with Advanced Conditions (VBScript)

Hello
I am truing to set up a workflow, were one of the States has to have a precondition with multiple metadata properties. In the object metadata card I have an Engineering Responsible and a Project Manager, Next state should be allowed only if one or both fields are filled. When using Property condition definition it works on AND principle, so I can set if both are filled.
I would like to try to set the condition using the Advanced Conditions(VBScript) option. How do I set the output? What property o variable I should set to allow or block the state transition?
So far I have this code, but what should be set if the condition is met?
Option Explicit

' Get Engineering responsible.
Dim szEngineeringResponsible
szEngineeringResponsible = PropertyValues.SearchForProperty( 1644 ).TypedValue.DisplayValue
if szEngineeringResponsible <> null then

???????

end if
 
  • Rather than using preconditions you could place your script in the trigger of a transition. In that case output should be AllowStateTransition = True (or False if conditions are not met).
    To avoid complex scripting with OR conditions you can add more than one transition and place different trigger scripts in each, and you can prioritize them to make sure the conditions are checked in a specific order.
    I am not sure exactly what the output should be in pre- or postcondition scripts, have never used them myself. Not much help to be found in the user guide. My best guess would be to try using AllowStateTransition.
    I find that the error messages provided to users when preconditions are not met generally cause a lot of confusion. If, for instance, you set preconditions to "x-property" is not empty, then users will get a message along these lines: The condition "x-property" is not empty is not met. This can be hard enough to understand if you are fluent in English. It is utter jibberish to people native in other languages. Therefor I tend to avoid such preconditions when possible.
  • Unfortunately placing the code in to the transition trigger, does not help my case. Problem with using the code in the trigger is that it triggers the transition as soon as first criteria is met not all of them and it does so with out permission from the user. In my case I need to have ether Engineering Responsible or Project Manager fields filled or both in addition to other metadata properties. In case o the trigger code, as soon as the user enters the Engineering Responsible and saves it, state changes, when user might wanted to fill in some other data as well, before sending it thru. As soon as the trigger transition is placed, the state becomes invisible to the user and they can not trigger it manually.
    I tried using the AllowStateTransition=True statement in the state precondition, but it is not recognised as an output. M-files sees it as just another variable, that does not have any impact on allowing or forbidding the actual state transition.
  • Did a little searching in the forum and came across a post from 2016, where Craig Hawker mentioned the use of error message as means to stop a transition: community.m-files.com/index.php
    In your case you could specify a message something like
    Err.Raise MFScriptCancel, "Responsible Engineer must be specified before moving to the next state"
  • Thank you very much, that helped! I still could not set the Advanced conditions, but I created a buffer workload state and added a script to the Actions->Run script option. In this case user can save all the data to the document and metadata card and move the document to the next workflow state. That will trigger the script, that checks if the requested fields are filled and then ether shows an error message and moves the document back to the previous state, or if everything is OK then it moves it to the next workflow state.
    Option Explicit

    Dim iWFState ' Define Workflow state variable.
    Dim szTrigger ' Define Trigger variable.

    ' Get Engineering responsible.
    Dim szEngineeringResponsible
    szEngineeringResponsible = PropertyValues.SearchForProperty( 1644 ).TypedValue.DisplayValue

    ' Get Purchasing responsible.
    Dim szPurchasingResponsible
    szPurchasingResponsible = PropertyValues.SearchForProperty( 1645 ).TypedValue.DisplayValue

    'Logic test if the fileds are not empty then set next state if they are set previous state.

    if len(szEngineeringResponsible) <> 0 or len(szPurchasingResponsible) <> 0 then

    iWFState = Vault.WorkflowOperations.GetWorkflowStateIDbyAlias("WF.Next state")
    PropertyValues.SearchForProperty(39).TypedValue.SetValue MFDataTypeLookup, iWFState

    else

    iWFState = Vault.WorkflowOperations.GetWorkflowStateIDbyAlias("WF.Returntopreviousstate")
    PropertyValues.SearchForProperty(39).TypedValue.SetValue MFDataTypeLookup, iWFState
    Err.Raise MFScriptCancel, "At least one Responsible must be specified before moving to the next state"
    end if


    'Save the changed propertyvalues to the object
    Vault.ObjectPropertyOperations.SetAllProperties ObjVer, true, PropertyValues



    I found one more way of doing it with out scripting at all, but it is not so elegant, but might come in handy for someone else.
    I created a new property in the Metadata card. Named it "Responsible field" in the Automatic Values tab, set Simple concatenating of properties and added both place holders of the Engineering and PM responsible properties there. Then I set that property as hidden so users can not see it.
    If Engineering responsible or PM responsible or both are filled the new property also gets a value, if not it also stays empty.
    Then in the workflow state preconditions I set the "Responsible field" as "is not empty".
    This way if the automatic value is filled then the transition can move to the next state if not users get an error message that "Responsible field" can not be empty.