NullReferenceException on SPWorkflowTask.AlterTask ()
In a custom task edit form for a custom content type, the following code is used to update the task item:
Hashtable taskHash = new Hashtable();
taskHash["Status"] = "Approved";
taskHash["PercentComplete"] = "1";
SPWorkflowTask.AlterTask(this._taskItem, taskHash, true);
This works great most of the time, however, if the custom content type defines no fieldrefs, or more specifically, the content type XML does not have the node, as could be the case if only a custom form is included in the custom content type, the following exception would be thrown on the AlterTask line:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="Microsoft.SharePoint"
because there is no columns in your task list ( you should not refer any fields in your content type).
So To fix this error, make sure that the node is in the content type definition XML, even when there're no child nodes.
Hashtable taskHash = new Hashtable();
taskHash["Status"] = "Approved";
taskHash["PercentComplete"] = "1";
SPWorkflowTask.AlterTask(this._taskItem, taskHash, true);
This works great most of the time, however, if the custom content type defines no fieldrefs, or more specifically, the content type XML does not have the node, as could be the case if only a custom form is included in the custom content type, the following exception would be thrown on the AlterTask line:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="Microsoft.SharePoint"
because there is no columns in your task list ( you should not refer any fields in your content type).
So To fix this error, make sure that the node is in the content type definition XML, even when there're no child nodes.
Comments
Post a Comment