I really enjoyed developing custom workflows for SharePoint in Visual Studio 2010. By saying that I enjoyed, I meant that I enjoyed solving some head aching exceptions in completing the workflow development.
So, I have decided to write about the caveats to be taken care in developing Visual Studio Workflow.
NOTE: I’m not going to explain how to create a Visual Studio workflow as it is out of scope of this post.
I have created a Sequential workflow in which when an user is uploading a document to a document library a task with custom content type that I developed would get created for another user to approve the document. Once the user approves it, the workflow status column text would read as “Approved” which is our custom status column value.
Below are the exceptions that I faced after deploying the workflow:
1. When the user uploaded the document to the document library, I expected the workflow to create a task with the custom task content type that I developed but instead the workflow status message read “Error Occurred” as shown below.
And also I found the below error in the workflow status page which says “An error has occurred in ReviewWF”:
I could not find an explicit exception message describing the reason for the error either in the Workflow history list or in the Event viewer. So I decided look at ULS logs where I found the below error stating:
“The content type of a workflow task must be derived from the Workflow Task content type.”
After seeing the above error I got to know that when I created my custom task content type in Visual Studio I chose the base content type to be Task as shown below:
This is not the correct way to create a custom task content type for workflow. The base content type should be Workflow Task Content type which is not listed in the above list (I’m wondering why it is not listed).
In order to associate our content type to workflow task content type we need to change the ID property of our content type. Initially when I chose Task as the base content type the ID property for the content got created as “0x010800e0b69596ca8143379c6484a932beaeea” in which 0x010800 in the beginning represents the ID of the base content type: Task, which has to be replaced by 0x01080100 which is the ID of the Workflow task content type. Finally the new content type will look like: 0x01080100e0b69596ca8143379c6484a932beaeea.
Now after I deployed the workflow, custom task got created successfully.
2. I had listed my custom workflow status column values in the Element.XML within ExtendedStatusColumnValues tag of my workflow as shown below:
When the approver approved the document, the value in the status column got changed to “Approved”:
Now, I wanted the value to be “Finished” instead of “Approved”. So I changed the value accordingly in the element.xml and re-deployed it. But when the approver approved the document the status column value of the workflow was still reading “Approved” as shown below:
This was giving me headache for a long time until I discovered that removing the workflow from the library and adding it again had it working. Now I get the correct value in the workflow status column as shown below:
To remove the workflow you need to go to the workflow settings of the library and select Remove a workflow, select the radio button below the Remove column for the corresponding workflow and click Ok as shown below:
I’m yet to figure out why is it so. Removing the workflow also deleted the workflow history of all the previously added items leaving no record of its past which is a huge limitation.