State machines are a wonderful thing to easily control, manage and administrate long running business processes. For those of you who don't know what state machines are and why you should use them, I have put together a post on my personal blog which you can access here.
The purpose of this post is not to reiterate any content from my blog but to provide you with a template that I regularly use. Hopefully it provides a common standard for everyone and you agree with the approach taken.
The following items will be required to make this template work:
- A status column on the list/library to track the process stage as part of each item
- The sub-processes should exist on the corresponding library or list.
- A standard error handling process. This could be implemented as a UDA (User Defined Action)
What's the structure of the template?
There is three main parts to the template:
- Initiation: This part of the state machine checks the current status of the process, based on the item's status column. It then changes to the correct state of the process. Very helpful in cases where you have to restart a workflow at a certain stage.
- State 1-3: They essentially are the various stages in your process and are only place holders that can be adjusted, added to, remove, based on your process' requirements. As part of the template, each state has actions to set the status of the process and then start a sub-process.
NOTE: there is no Change State actions in the State 1-3 branches of the state machine. Remember do put those in, according to your process flow. Otherwise you might end up running around in circles when testing your state machine and not going anywhere.
- Error Handling: The action set is a place holder for you to incorporate any error handling you might have to put in place. That way you can gracefully stop workflows and get someone to look at the issue, rather than just having it fail. There are numerous actions (especially integration actions) that allow you to capture errors. Following the workflow template, the process will start at the correct state when restarted, rather than from the very beginning.
Hope this helps some of you and happy for any feedback you might have.