I'm running into an issue with a custom approval workflow that was written in visual studio. It creates an approval task using a custom content type. I developed the workflow on a sharepoint enterprise environment, but the client is trying to run it on a foundation server. The issue I'm running into is when the content type is assigned to the task list. Whenever the workflow is run, I am unable to edit the list item, or update the task item. As soon as I remove the content type from the task list, I can view and edit all of the records just fine. I do get the following event in the logs:
System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.SharePoint.Publishing.CachedListItem.GetWorkflowInfo(SPListItem item) at Microsoft.SharePoint.Publishing.CachedListItem
To make it more interesting, I was able to run the workflow when the content type was not assigned and get the approval task created, then add in the content type after, then successfully edit and update both records.
And a bit of code.... this is my create task with content type method:
private void createTaskWithContentType1_MethodInvoking(object sender, EventArgs e)
{
//set the primary approval task as not completed
this.primaryApprovalTaskCompleted = false;
//get the primary approver
var field = workflowProperties.Item.Fields.GetField("primaryApprover") as SPFieldUser;
var fieldValue = field.GetFieldValue(workflowProperties.Item[field.Id].ToString()) as SPFieldUserValue;
createTaskWithContentType1.TaskProperties.AssignedTo = fieldValue.User.LoginName;
createTaskWithContentType1.TaskProperties.DueDate = DateTime.Now.AddHours(4);
createTaskWithContentType1.TaskProperties.Title = "Primary Approval for Batch Job ID: " + workflowProperties.Item["batchJobId"].ToString();
createTaskWithContentType1.TaskProperties.SendEmailNotification = true;
}
and the xml for my content type:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field ID="{46F9442F-19E3-4818-8FE7-719E5961C8A1}" Name="ApprovalStatus" DisplayName="Approval Status" Type="Choice" Required="TRUE" Sealed="TRUE" Overwrite="True" >
<CHOICES>
<CHOICE>Approve</CHOICE>
<CHOICE>Reject</CHOICE>
</CHOICES>
</Field>
<Field ID="{B485C5E5-A85C-4C09-AE96-F7FC71FB4A3D}" Name="ApprovalNotes" DisplayName="Approval Notes" Type="Text" Overwrite="True" />
<ContentType ID="0x01080100922FA9051D1C471DA956E627E6B3B81E"
Name="ApprovalContentType"
Group="Custom Content Types"
Description="Approval Content Type"
Version="0"
Overwrite="True">
<FieldRefs>
<RemoveFieldRef ID="{a8eb573e-9e11-481a-a8c9-1104a54b2fbd}" Name="Priority" Hidden="TRUE"/>
<RemoveFieldRef ID="{c3a92d97-2b77-4a25-9698-3ab54874bc6f}" Name="Predecessors" Hidden="TRUE"/>
<RemoveFieldRef ID="{c15b34c3-ce7d-490a-b133-3f4de8801b76}" Name="Status" Hidden="TRUE"/>
<RemoveFieldRef ID="{d2311440-1ed6-46ea-b46d-daa643dc3886}" Name="PercentComplete" Hidden="TRUE"/>
<RemoveFieldRef ID="{7662cd2c-f069-4dba-9e35-082cf976e170}" Name="Body" Hidden="TRUE"/>
<FieldRef
ID="{46F9442F-19E3-4818-8FE7-719E5961C8A1}"
Name="ApprovalStatus" Sealed="TRUE" Required="TRUE"/>
<FieldRef
ID="{B485C5E5-A85C-4C09-AE96-F7FC71FB4A3D}"
Name="ApprovalNotes"/>
</FieldRefs>
</ContentType>
</Elements>