|On a recent project we have had the need to create a workflow that is associated with a content type. This content type is published globally and then used by all site collections in the farm. The new content type publishing features in SharePoint 2010 will get us half way there. Using these features we can publish our content type, however our workflow will not publish with the content type. This means that we need to come up with an alternate approach to making the workflow available.
Now, this is where we begin to have several options, and each option has pros and cons. For the purpose of this blog post I am going to be walking you through the process of creating the workflow in SPD, saving it as a template and adding it as a solution to the site collection where the content type is published. This is a manual step, so I understand fully that this might not work in all scenarios. Like all things SharePoint though, you will need to look at the pros and cons of each option and choose the one that best fits your scenario.
This Post Applies To:
|Step 1: Create the Custom Content Type
For this step, we will need to access the content type hub. If you are you the server administrator then when you configured the Managed Metadata Service Application this is the same site collection you configured to be the hub. If you are not the server administrator then you will need to work with your SharePoint Governance team to determine your access to this location. Since this is a global location that effects the entire farm, it is very likely (or should be likely) that there are governance policies in place to identify who has access. Below is a screenshot that shows this configuration setting:
Once we know the URL of our content type hub, we will access this site collection and create the content type just like any other site collection.
For my example, I am going to create a Content Type Called Custom Document, with an associated Column called Custom Text.
Once we create the column, we will edit the properties so that it becomes a hidden field (hidden means that it will be available for views, but wont display on the create and edit forms).
Step 2: Create the Reusable Workflow
Now that we have the content type in place, we need to create our reusable workflow. For my example I am going to create the workflow from the content type hub site collection. My workflow is going to be pretty basic. Whenever a document is created it will be assigned a custom number based on the user and the created date. This is just an example to get you started. Any workflow that can be created as a reusable can be created in this step; I just want to keep it simple for this example.
In the workflows menu, select to create a reusable workflow:
Select the Custom Content Type that we created in the step above:
Add your workflow steps. In our example we are going to set the value of the column we created in the step above*. Once you have completed the changes, publish the workflow.
*Note: If you don’t see your custom column, edit your content type so that the field isn’t hidden. Set the value in the workflow and then reset the field to hidden.
Step 3: Save the Workflow as a Template
Navigate to the Workflow settings page and from the Ribbon, select the option to save the workflow as a template*.
*I recommend testing the workflow fully before completing this step. No sense in making a template before you know if it works or not
Once the template has been saved, you will see a message that tells you that the template has been saved to the site assets library.
Now, we will access the site assets library and export the .wsp we just created. When you select the export option, you will want to export to a location that we can access in the next step.
Step 4: Upload Solution & Activate Feature
Now we will need to return to the site collection that has the content type and upload our reusable workflow to the solutions gallery.
Upload and activate the solution file we saved in the previous step.
Activating the solution is just part of the process. The activation makes the workflow available, but in order to use the workflow we first need to activate the feature. We will need to access the site features and activate our custom workflow.
Step 5: Associate the Workflow to the Content Type
Now we will open the settings for our custom content type and add the workflow association.
Select the custom workflow from the options and enter the required information.
Step 6: Publish the Content Type
Now that our content type is ready to go, we will publish the content type. The publishing action lets the service application timer know that a new content type is ready to be pushed down the next time the timer runs. This typically runs every hour so keep in mind that it might not be immediately available in all the site collections.
Step 7: Add the Workflow Solution to the other Site Collections
Once the publishing timer runs, you should be able to access another site collection and see that your custom content type has been published. Since we haven’t yet installed the custom workflow, we will see the content type but will also see an error in the publishing log.
To access this information, select the Content Type Publishing option on the Site Settings Page-
You should see your custom content type displayed with the Subscribed Content Types.
When you select the link to open the error log, you should see an entry similar to the screenshot below. This is because the associated workflow is not activated within this site collection.
To fix this error, we simply need to upload the workflow solution to the site collection and activate the workflow feature. You can do this by repeating step 4 in each of the site collections that is going to use this workflow.
Yes, I know this is a very manual step! But that is why at the beginning of the blog I said you have other options (think custom development or PowerShell scripts – depending on your platform). The purpose of this blog is just to highlight the manual steps. Besides you can’t really know how to automate things until you fully understand how to do them manually.
Now, the next time the process runs you will not have an error in the log. You can now add the content type to the document library and once you upload a document the workflow should automatically start (it only starts automatically because I configured it to run when a document is uploaded, it will trigger based on your earlier configurations).