The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

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

Automate change of WF to new WF based on specific state

We have a Workflow that is being replaced by a new one.  All documents in the Client with the existing workflow applied need to change over to the new WF based on a specific state.  I wanted to automatic the change to a new Workflow and its corresponding state.  Is there a way to achieve this?

When the existing WF is 'effective' (pdf) as soon as the permitted user applies a 'new revision' a script creates a new document and using a copy from the effective version (prior to the pdf conversion) and sets the state to 'draft'.

Once the document is in draft at this point I wanted to change the workflow over to the new one and apply the new state as we have thousands of documents this will apply to.

I have tried to use Hierarchy Manager but it doesn't seem to work so my only other thought was the possibility of updating the script to changing the WF but not sure if this would work.  

Any ideas greatly appreciated.

Parents
  • This script can be used with a few changes to define the new workflow and state.

    'General script for changing workflow and or state as State Action
    '2021.07.09 Karl Lausten
    Option Explicit
    'clear State
    Dim oStProperty : set oStProperty = CreateObject("MFilesAPI.PropertyValue")
    oStProperty.PropertyDef = 39
    oStProperty.TypedValue.SetValue MFDataTypeLookup, Null
    Vault.ObjectPropertyOperations.SetProperty ObjVer, oStProperty
    'prepare WF
    Dim oWFProperty : set oWFProperty = CreateObject("MFilesAPI.PropertyValue")
    oWFProperty.PropertyDef = 38
    'determine future workflow and state (if conditions are required, insert relevant "if" statements)
    Dim iWFnew : iWFnew = Vault.WorkflowOperations.GetWorkflowIDbyAlias("<new workflow alias>")
    Dim iWFnewState : iWFnewState = Vault.WorkflowOperations.GetWorkflowStateIDbyAlias("<new state alias>")
    'set new workflow and state
    oWFProperty.TypedValue.SetValue MFDataTypeLookup, iWFnew
    Vault.ObjectPropertyOperations.SetProperty ObjVer, oWFProperty
    oStProperty.TypedValue.SetValue MFDataTypeLookup, iWFnewState
    Vault.ObjectPropertyOperations.SetProperty ObjVer, oStProperty
    

  • Hi Bright-ideas.dk

    I gave your script a try by creating a test WF based on the old WF that is being replaced and added a new state including your script (updated) after it has transitioned to draft.  The reason I did this is because the Amend New Revision state has a script as noted initially but so does the Draft state it transitions to.  I ran the test WF but it keeps defaulting back to the old Workflow and stops at draft.

    I have adjusted the existing scripting to point it to my test workflow in terms of the IDs that were detailed but that hasn't made any difference.  I think the draft state is forcing the old workflow. 

    I appreciate your time to help me

  • Hi Kelly,

    Not sure exactly what goes on. Sounds like you have several automations going on to send the new document in different directions. When you create the new document as a copy of the "effective state" from the original document you should in the same script set the correct workflow and state before saving the new document. This would ensure that the new document comes directly into the new workflow. Then in that new workflow you need to remove anything that might send a document back to the original workflow. If you use IDs directly you have to make absolute sure that you have the correct IDs. If you use Aliases, make sure you don't use the same Alias in both workflows.

    Hope you can get it right. It is a bit difficult to advice without a clear picture of your setup.

    BR, Karl

  • Thanks Karl, all useful points to factor in.  Thank you for your help.

Reply Children
No Data