How to: Access Workflow Task Form Data in a Workflow in SharePoint Server 2010 (ECM)
Last modified: May 07, 2010
Applies to: SharePoint Server 2010
When you create a workflow task, its property data comes from an SPWorkflowTaskProperties object, which you can access through the TaskProperties property of the CreateTask activity. This object contains information that is standard for every workflow task, as well as any custom properties contained in the task schema. By initializing the SPWorkflowTaskProperties object variable you specify for the TaskProperties property, you can use the task data passed to the workflow.
The SPWorkflowTaskProperties object you access through the TaskProperties property simply contains initialization information about the newly created task; it is not dynamically bound to the task itself in any way. Changes made to the task are not reflected in the data stored in this SPWorkflowTaskProperties object.
In addition, the object also contains a hash table, represented by the ExtendedProperties property, to store custom task properties. You can access a specific custom property by passing the property name as an index for the ExtendedProperties property.
Microsoft SharePoint Server 2010 names each custom data value in the hash table after the task field that contains the data. For example, if you have a text field in your workflow task named comments, the index name of that field's data in the ExtendedProperties property hash table is comments as well.
The ExtendedProperties hash table is populated with both standard fields and custom fields. However, the standard workflow task type fields are represented with GUID indexes, rather than with their names, to prevent possible name collisions with custom fields of the same name. We recommend you access standard workflow task fields through their respective properties, rather than through the ExtendedProperties hash table.
In general, bind the TaskProperties property of each task-related activity to the object variable you defined for the TaskProperties property of the CreateTask activity that created that specific task. This object variable is used as a conduit to pass data into the task.
For more information about setting activity properties, see the Windows Workflow Foundation SDK.
Data from a Microsoft InfoPath 2010 workflow task form is not passed directly into the workflow, as it is for workflow association or initiation forms. Rather, the task form changes the fields corresponding to the form schema in the task item directly; these changes are passed into the workflow only if the workflow is waiting for an OnTaskChanged event. To receive data from an InfoPath form, you need an event receiver activity for the corresponding event, such as OnTaskChanged. The SPWorkflowTaskProperties object bound to the AfterProperties property of the OnTaskChanged object stores the fields in the task that have changed (and only those that have changed). By default, an InfoPath form will alter the task using fields that match the form's schema.
To access workflow task form data in a workflow
If the data is from a standard workflow task field, access it by using the applicable property of the SPWorkflowTaskProperties object.
For example, suppose you set the AfterProperties property of the OnTaskChanged activity for your workflow task to an SPWorkflowTaskProperties object variable named wfTaskProps. To access the AssignedTo property, you refer to it in your code as follows:
For example, to access a custom property named comments, refer to it in your code as follows: