An interesting topic arose on Nintex Connect, regarding having the same workflow on a number of lists and libraries, and how one would go about updating all of them. This is especially important, given that in the SharePoint 2007, you can’t create a declarative workflow for a Content Type.
You could create a workflow, save it as a template, and then create workflows on all your other lists/libraries based on this template. But the issue is, there’s no way to update this in a central place, that would then go and update all the other workflows you created from this template.
Most companies have QA/Test environment where the workflow is designed, and then once they are happy with it, they push that workflow into their production environment. So I’m going to use a similar design.
I am going to have a central place/site where I create workflows, then once I am happy with it, I will export it through the Nintex Workflow Designer to a NWF file.
I have one List which will be treated as a Lookup list. It will contain the name of the workflow I should look for, and the destination list that needs updating, and also what the workflow is named on that destination list. SharePoint has a limitation that you can not use the same workflow name multiple times in the same site.
I will then have a Document Library where I will upload my exported NWF file and a workflow will start off that will figure out what lists/document libraries require this workflow to be published on.
Lookup List name : Workflow to List Map
Workflow Document Library : Master List of Workflows
eg. List to be updated : List1
eg. Document Library to be updated : DocumentLibrary1
Main List and Document Library
The Master List of Workflows document library will be the location where you would upload your Nintex Workflow export file (NWF).
As you can see, there is nothing special with this document library. It will only hold the NWF files.
The Workflow to List Map list, is a little different. This is a standard SharePoint Custom List, where I have renamed the Title field to “Workflow Name”, and added 2 Single line of text fields (Destination Workflow Name and List Name).
The List1 and DocumentLibrary1, are just a simple List and Document Library, where I want to publish my workflow/s.
In the screenshot above, for my “Workflow to List Map” list, I have added 2 entries. Both are for the workflow file named “SimpleWorkflow.nwf”. The first entry is telling us that that workflow should be updated in the List “List1” and the name of the workflow should be “Simple List Workflow”.
The second entry is for the same workflow filename, and this time we are updating a list (document library) named “DocumentLibrary1”, and call the workflow “Simple Document Library Workflow”.
I won’t focus on how to export a workflow. Suffice it to say, I create a simple workflow with just a Log in the History List action in it.
Once you upload your NWF file to the “Master List of Workflows”, this workflow will start.
You can see that it is not a very complicated workflow. The pseudo-logic is below :
1. Query the Workflow to List Map list, for all List Names where the “Workflow Name” matches the uploaded NWF filename.
2. Query the Workflow to Lsit Map list, for all Destination Workflow Names where the “Workflow Name” matches the uploaded NWF filename
3. Use the Query XML action, to get all the XML of the NWF file
4. XML Encode the XML we have retrieved. (I didn’t use the fn-XmlEncode inline function, because I had some issues with it).
5. Loop through the List of destination List Names, and publish this this workflow.
Looking a little deeper into the For Each action, we see the following :
What I am doing here, is iterating through my collection of destination List Names, and the getting the associated Destination Workflow Name from my other collection variable.
Then we have the important part, which is calling the Nintex Workflow web service. This you can find here : http://<server>/<site>/_vti_bin/NintexWorkflow/Workflow.asmx
This web service exposes a number of web methods, but the one I was most interested in for this issue, is the PublishFromNWFXml method. This method takes the NWF Xml that XML Encoded earlier, the destination List Name and the Destination Workflow Name (also a saveIfCannotPublish parameter, which I just set to true).
I complete the For Each action, by using a Set a Condition action, to check if the Call Web Service action completely successfully or not. If it hasn’t, I email the Initiator of the workflow, the data that was returned to us from the Web Service, and also any error that was caught. That way, the Initiator of the workflow will know something has failed, and also know the reason and can fix it, and restart the workflow.
What happens when the workflow runs?
When we run the workflow on the uploaded NWF file, the workflow will then publish this workflow on the destination Lists and Document Libraries. You can tell, by going to one of the destination lists, and going to Manage Workflows :
When the page comes up, you’ll see that the newly added workflow is a Published state.
This workflow should have the name, as specified by its entry in the Workflow to List Map list. It will also has the same Startup Options as the workflow that you exported. So if you want this workflow to start when items are created, make sure you set that setting on the workflow you designed, prior to exporting it.
This is one way of making sure a workflow that you want on a number of lists and document libraries get published on those lists from a central source. This will also update any existing workflows. So if you already have a workflow named Simple List Workflow on your destination list, this process will update that workflow (including the version).
Test Workflow Design: Download Update Workflows workflow