How do I force an active Workflow to use a new definition?

August 30th, 2011 Matt

I was asked a few days back about whether there is any way for an existing Workflow process to be forced to use a new definition when the new version is saved to the database:

There is some transaction already in ACTIVE status ( i.e. ACTIVE workflows ) in database. I need to run this transaction according to new wft file what I have putted in database recently. Is is possible ?

The simple answer is: “it depends”!  Workflow allows multiple versions of the same process to exist in the database at the same time, so in this post, I’ll be looking at what you can do to use the new definition.

Workflow Automatic Versioning

When a new definition of an Item Type is deployed to the database, the Workflow Engine will automatically create a new version of some objects if they have been changed.  The objects which are versioned by the Workflow system are:

  • Notifications
  • Functions
  • Events
  • Processes and Sub-Processes
  • Process Activities (anything on the Node, Node Attributes or Event Details tabs for an activity)
  • Activity Attributes
  • Activity Attribute Values
  • Transitions

So, if you have made any changes to any of these things, when you save the definition to the database, a new version of the object will be created – any existing processes will continue to use the old definition rather than the new one.

If you have made any changes to Item Attributes, Lookup Types, Lookup Codes, Messages or the underlying PL/SQL code then those changes will immediately be picked up by processes which are already running and any new processes which are launched.  So, here’s a warning – if you are making changes to messages or lookups within a process, any changes you make will take immediate effect when the definition is deployed to the database.

Changing your PL/SQL will also impact the processes which are already running – particularly if the code references any new attributes which do not exist in the processes which are already running.  There are some things that can be done within the code to catch and handle any errors which may be thrown by attributes not existing – for example, you can include an exception handler which calls WF_ENGINE.AddItemAttr to add a new attribute if one does not exist in the definition.

Forcing Existing Processes to Use a New Definition

So, if you have made changes to the process which means that a new version has been deployed, what do you do with the existing processes?

The simple approach would be to abort the existing process and then re-run them from the beginning.  Some processes may include a mechanism for doing this, for example in an approval process, if a user rejects the request then the process may send it back to the requestor to resubmit.  However, if the process has been running for a long time, then it may not be practical to restart it.  Some years back, I worked with a business where their processes could run for years before completion, where aborting the process just wouldn’t be practical.

When an activity is started by the Workflow Engine, the engine determines which version of the definition to use by checking the begin date of the record within WF_ITEMS.  The date that the process started is then checked against the effective dates for the activities and the version which was current when the Workflow process started will be used to determine which activity to run and what the transitions are from the activity.

So, if you really, really need to force the running processes to use the latest definition, then you can update the BEGIN_DATE field for the record in WF_ITEMS to a later date.  When the next activity is executed, the engine will check the date and will use the latest version of the process.

There are two main drawbacks of having to adopt this approach.  Firstly, any reporting / auditing / metrics that you have for determining process execution time will no longer be accurate because the start date of the process has now been manipulated.  Secondly, if there are any problems further down the line with the process, then Oracle won’t support you – that said, if this is a custom process, then you won’t be getting much support from Oracle anyway…

As ever, make your changes in a test environment before making changes to your production system to ensure that everything still works, though.

Posted in Oracle, Technical | No Comments »

Why Funcmode is important

August 23rd, 2011 Matt

I recently had a question where the developer had built a process which included a loop.  Within that loop, there was a custom function which determined which level of approver was required before applying processing logic, something similar to this:

The problem was that when the “Do Something” step was being executed, it appeared that the “Find Approval Level” step was always jumping two levels – the first and third approvers were being found, but never the second or fourth.  So, there must have been something wrong in the “Find Approval Level” step if it was always jumping two levels, right?

Wrong!  The problem was that the loop activities in the process hadn’t been defined properly, and the code hadn’t been written correctly in a very basic manner.

The Workflow activities should have had the “On Revisit” flag set correctly for the activities that were in the loop.  The standard is to have it set to “Reset” which will re-run the activities in CANCEL mode before re-running the loop in RUN mode.  Instead, the activities should have had the flag set to “Loop”:

If the flag is set to “Ignore”, then the activity would only be executed once – which means that you would end up in a perpetual loop in this example, since the “More Required?” step would always return “Yes” unless there was only one approval level.

The basic change to the code is to check what the FUNCMODE is before doing any further processing.  If the code was written so that the search for the approver only happened during RUN mode, then the process wouldn’t appear to skip a level.  Unless there is specific code to undo an execution, then I always include a check at the start of my activities which says that if FUNCMODE does not equal WF_ENGINE.ENG_RUN (the externalized constant for RUN mode), then simply RETURN to the Workflow Engine.  This saves processing time and avoids problems like the one we see here.

Posted in Oracle, Technical | No Comments »

  • Pages

    • About Us
    • Services From WorkflowFAQ
    • Training
    • Workflow Book
    • Careers
    • Forum
    • Blog
  • Oracle 11i Workflow Certified Expert
    Oracle 11i System Administrator Certified Expert

  • Search


  • Blog

    You are currently browsing the WorkflowFAQ weblog archives for August, 2011.

    Archives

    • February 2012
    • January 2012
    • November 2011
    • October 2011
    • September 2011
    • August 2011
    • July 2011
    • June 2011
    • April 2011
    • February 2011
    • January 2011
    • December 2010
    • October 2010
    • September 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • October 2009
    • August 2009
    • July 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
  • Categories

    • General Computing (30)
    • Non-Oracle (18)
    • Oracle (78)
      • Functional (20)
      • Technical (69)
    • Personal (2)

  • Links

  • General Computing

    • Computing Magazine
    • Download.com
    • SourceForge.net
    • The Daily WTF
    • The Register
  • Non-Computing

    • BBC News
    • Burnley-based professional photography
    • Cuteable
    • My wife’s shop
  • Oracle Related

    • AppsDBA
    • Oracle
    • Oracle Apps Blog
    • Oracle Magazine Interactive
    • Oracle Support
    • Oracle Technology Network
    • Oracle UK
    • Oracle Workflow Forum on OTN
    • Oracle WTF
    • OraFAQ
    • Steven Chan
    • Steven Feuerstein


Copyright © 2012 TS Fifteen Ltd. All rights reserved.