Have you ever wished you could temporarily disable a SharePoint Designer workflow? You may want to do this in order to mass-approve a large number of documents without setting off dozens -- or possibly hundreds -- of unnecessary workflows.
One way to accomplish this is to access the workflow using SharePoint Designer and disable it. To do that, you’ll need to open up Share- Point Designer, access the workflow, change its properties and re-save it. The problem with that method is that it’s a little messy and likely to ring lots of alarm bells at most companies. In general, fiddling about with SharePoint Designer workflows is not a good practice in a production environment, nor is it part of a wellcontrolled process.
Want a better solution that allows you to enable or disable a workflow solution using a custom list? Wondering how to enhance it to make it more robust and useful?
It’s possible -- just access data from a custom list and use it in your workflow. Start by creating a custom list to hold the control information.
For our purposes, the control information is a simple Yes/No value indicating whether the workflow is enabled or not. At runtime, the workflow queries this custom list to determine whether it should operate or not. If the answer is “No,” the workflow gracefully aborts.
How to create an environment
To follow along with this process, create a document library and a custom list.
Add a new column named “Workflow Is Enabled” to the custom list “Workflow Control,” whose type is “Yes/No (checkbox).”
Using SharePoint Designer, open up the site and create a simple workflow solution on the document library -- “Managed Documents Approval.”
Note: This is an extremely simple workflow process designed to demonstrate the point. This approach will work, however, regardless of how many steps or how complex your real-world workflow is.
Click the Finish button, upload a document to the library and test the workflow. It logs a message to the workflow history list.
Implementing the control mechanism
The objective is to provide systems administrators with a mechanism that allows them to enable or disable a workflow without opening up SharePoint Designer. To accomplish this, you have to create a list named “Workflow Control” and add an item.
Make a note of the title, “Managed Documents Approval.” It doesn’t really matter what you give as a title, but it should be unique within that list. It should also clearly relate to the workflow you want to control with this setting. In this case, because I named the workflow itself “Managed Documents Approval,” I used the same name here.
Leave “Workflow Is Enabled” off (false). That means you don’t want the workflow to run.
In the final step, enhance the SharePoint Designer workflow to take advantage of the control information in this custom list. Fire up SharePoint Designer again and pull up the workflow. Add a new step:
- Step Name: “Access WF Control List and Continue/ Abort as Indicated”
- Add a condition: “Compare any data source”
Click on the little F(x) button to pull up a set of dialog boxes. This is a common SharePoint dialog. You use this dialog box to tell SharePoint workflow to do two things:
- Get a piece of information.
- Describe how to find that information.
In this case, you’re telling SharePoint Designer to get the value of the column Workflow Is Enabled from the custom list Workflow Control where the title equals Managed Documents Approval.
FIGURE 6 displays what SharePoint Designer says when you click the OK button in FIGURE 5.
In this case it's not a problem, but it could be a problem. What would happen if two entries were created in the Workflow Control List, both with the title “Managed Documents Approval”? At runtime, workflow wouldn’t know which one to pick, so it would pick one on its own. SharePoint administrators must ensure that they use unique names for their workflows. Otherwise, the results may be unpredictable.
FIGURE 7 shows what the new workflow looks like.
Note that a new step was added and moved to the first step in sequence. This is important. Otherwise, the logic would execute after the workflow proper and defeat the whole purpose of this exercise.
Now the workflow can be tested. To complete the test, go back to the workflow control list, edit the lone item and change the value of “Workflow Is Enabled” to Yes (check the checkbox). Re-run the workflow, and it won’t abort this time.
Extending the solution
As it stands, this solution allows SharePoint administrators who are responsible for a given workflow process to enable or disable the workflow as needed. To make this solution even more useful, consider the following enhancements:
Version control. Enable version control on the list. This will provide an audit mechanism and auditors can determine every time the workflow is disabled or enabled by looking at the version history of the list.
Security. Turn on item-level security. Configure security in such a way that a “super” administrator can create and update items in the control list and that lower-level administrators are allowed to only update the list— not create or delete items. Finally, it allows everyone that would ever run that workflow to read from the list— and that’s important. The workflow will always attempt to read from that list. If a given user does not have read access to the item, the workflow process will fail for them.
Multiple workflows. This solution allows you to control more than one workflow with the list. Use it for that purpose if it makes sense in your organization. Just be sure to keep the names unique or you will run into problems.
Workflows change over time, which is a challenge in a SharePoint environment that leverages SharePoint Designer for workflow solutions. SharePoint Designer does not provide any kind of version control on a workflow itself. If you go live with a workflow onMonday and want to change it on Tuesday, you have a problem on your hands, particularly when Monday’s workflows are still running.
What happens to those workflows when you update the system on Tuesday? It’s not pretty. So instead of updating the existing workflow, simply create a new one with the same name but with a version tagged to its name. DisableMonday’s workflow to prevent any new processes from starting. That allows any in-process Monday workflows to complete, and any new workflow processes will use the new version.
Couple this with version control on the list level and you have a well-controlled environment to manage your SharePoint Designer workflow solutions. The technique is a simple one, but it offers an effective way to keep workflow in check.
About the author:
Paul Galvin is aMicrosoft SharePointMVP and a SharePoint solutions architect at EMC Corp. Galvin has worked in the IT industry for more than 15 years in areas such as software development, consulting and SharePoint solutions design, where he works with clients to create business solutions using the SharePoint platform. He contributes to the SharePoint community throughMSDN forums and his blog at http://paulgalvin.spaces.live.com.