Tuesday, February 21, 2012

Assign a Custom Content Type to Task Process in a SharePoint Designer 2010 workflow

SharePoint Designer 2010 has some awesome new features!  Two of my favorites are (1) the ability to copy and modify an out of the box workflow and (2) the custom task processes.     

What I don’t love is the way SharePoint assigns names with spacing to these tasks that have “_X0028_” and “_X0029_copy” in it.  It can cause problems with importing the workflow into Visual Studio, referring to the content type in custom web parts, and as an architect, I just don’t like the way it looks too messy.  Plus, if I want to make changes to the task list or roll the task up in a web part, I don’t want to have to guess which task goes with which workflow. 

Here is an example of what SPD does when it adds a custom task action to a workflow or when you copy out of the box (OOB) workflow:


And this is what I want it to look like: 


And it’s not just aesthetics; I have certain fields that I want to be able to store in the task.  I know that I can assign them in the workflow task process, but I don’t want the end user to see them so I want them hidden.

Here are the steps:

1.       Create your custom content type at your parent site (or content hub).

·         Important note:  If you are going to be exporting your workflows to other environment (i.e. local to production) and you do not use a content type hub, I STRONGLY recommend creating these content types and any site columns associated with the workflow with code.  This will ensure that your GUID’s (custom ID’s) are the same across all environments.  

-   I worked with a developer to create my site columns and content types for me since we are moving workflows across environments

-   If you do not have access to a developer, then you will need to replicate these steps in each environment to make sure the ID’s are correct for each. 

2.       Optional Step:  If you want the “Claim Task”, Custom Outcomes functionality, and the ability to Reassign or Request Changes that comes with the out of the box workflow tasks for Enterprise SharePoint, you will need to change the display and edit forms.  If not, you can skip this step.

 Example of InfoPath display form vs .aspx display form

·         If you create the content type in Code, make sure the display and edit form properties include “_layouts/WrkTaskIP.aspx”

·         If you create the content type by hand (or did not assign a display/edit form specification in the code), open the content type in Designer and change the display and edit form to “_layouts/WrkTaskIP.aspx” under “Forms” on the right side of the screen.

3.       Create your workflow

·         Either Copy and Modify an out of the box workflow

·         OR Create a new workflow and add a custom task process – Start Approval Process, Start Custom Task Process or Start Feedback Process

-   (I have not tested this with the other task actions)



4.       Save the workflow, but do not publish it.

·         NOTE: If you have published it and have the odd-named content type, just delete that task form.  We will generate a new task form at the end.

-   This odd-named content type will exist in your Content types library until you delete it from there


5.       Open the custom content type you created in Designer and Copy the ID


6.       Go to All Files, Workflows, <WorkflowName> folder

·         Note: If the “All Files” folder looks empty, click on another folder, such as subsites, and select “All Files” again.



7.       Open the file that ends in  “.wfconfig.xml” and replace the following items:

·         Line 2: TaskContentType=”<ID>” with your custom content type

·         Line 4: ContentType Name=”<Name>” with your custom content type name

·         Line 4: ContentTypeID  = “<ID>” with your content type ID you copied from previous step

·         Line 4: WorkflowForm= “Workflows/<workflowname>/<contenttypename.xsn>” with your content type name (just the name of the form, leave the folder name as is


 Here is what it should look like (my content type is “IntakeReviewTask”)

*Line 2 not pictured


8.       Save the the xml file and go back to your workflow folder


9.       Hover over the file that ends in “.xoml” file and select “Open with”  -> “2. SharePoint Designer (Open as XML)”. 


10.   Click (Ctrl+F) for Find and enter “ContentType” in the “Find what” box

11.   Replace the ContentTypeID=”ID” with your custom content ID


12.   CLOSE SharePoint Designer and re-open it. 

 ·         Refreshing has not worked for me.


13.   Open Designer, open your workflow by clicking on “Workflows” and Save your file.   Click “No” if you receive any messages to replace your file.


14.   Publish your workflow.  The right side of the picture below shows my workflow after completing this process.

And Voila, no more messy names and you can use your custom content type for whatever you may need, displayed in a CQWP, for example.