Windows SharePoint Services sends the data from Office InfoPath 2007 forms used in workflows to the workflow instance as XML. This includes the contact data specified by the user in the Contact Selector control. To use this data in the workflow, you must parse the form XML passed to access the contact data.
The location to which Windows SharePoint Services passes the form XML data depends on the type of workflow form:
-
For workflow initiation forms, Windows SharePoint Services passes the entire form data as an XML string to the WorkflowProperties.InitiationData property of the OnWorkflowActivated activity.
For more information about this workflow activity, see the Windows SharePoint Services 3.0 SDK.
-
For workflow modification forms, Windows SharePoint Services passes the entire form data as an XML string to the ContextData property of the EnableWorkflowModification activity.
For more information about this workflow activity, see the Windows SharePoint Services 3.0 SDK.
For information about the schema of the contact data XML, see How to: Configure a Contact Selector Control on Your InfoPath Workflow Form.
You can use two approaches to parse the form XML to retrieve the contact data:
-
Use helper classes included with Office SharePoint Server 2007. The Microsoft.Office.Workflow.Utility namespace contains classes, such as the Form and Contact classes, that are designed to help you deserialize and access the contact data.
The Form class includes a method to deserialize an InfoPath form field into a hash table object, with key-value pairs corresponding to the fields of the form.
The Contact class includes methods to serialize and deserialize the Contact Selector data, and to access the relevant data for those contacts.
-
Use the XML deserialization functionality included in the Microsoft .NET Framework 2.0.
For more information about workflow association and initiation forms, see Workflow Association and Initialization Forms.
To access Contact Selector control data in workflow initiation or modification forms by using the Form and Contact classes
To access Contact Selector control data in workflow initiation or modification forms by using the .NET Framework XmlSerializer class
-
Extract the schema of your initiation or modification form.
-
In Office InfoPath 2007, open your saved and published workflow form.
-
On the File menu, click Save as Source File. Browse to the location to which you want to save the form source files, and then click OK.
InfoPath saves a collection of form source files, including the schema file, to the specified location. The form schema file is always named myschema.xsd.
-
Use the Microsoft Visual Studio 2005 command line tool xsd.exe to generate a new class file from the form schema. By default, Visual Studio 2005 installs the xsd.exe command line tool to the following path, where C: represents the drive on which you have installed Visual Studio: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin.
-
Open a Visual Studio command line prompt. Click Start, point to All Programs, point to Microsoft Visual Studio 2005, point to Visual Studio Tools, and then click Visual Studio 2005 Command Prompt.
-
Navigate to the location of the form schema (.xsd) file, and then run the following command: xsd myschema.xsd /c /o:output_directory.
This command generates a new class file based on the form schema, named the same as the schema file. The class in the file is named the same as the root element of the schema, which was named the same as the form fields collection.
The class contains an array of type Person, with the same name as the Contact Selector control on the form.
-
In Visual Studio, add the new class file to your workflow project.
-
Include code in your workflow that deserializes the entire XML form string into an object whose type is that of the class you generated from the form .xsd file.
In the following example, the form fields collection is named MyFields, so the class generated from the form .xsd file is also named MyFields.
XmlSerializer serializer = new XMLSerializer(typeof(MyFields));
xmlTextReader reader = new XMLTextReader(new
System.IO.StringReader(workflowProperties.InitiationData));
MyFields fields = serializer.Deserialize(reader);
-
To access the contact information, include code that accesses the form information by using the various class properties, which are named the same as the various controls on the form.
In the following example, the Contact Selector control on the form is named Users. Therefore, to access the accountID data of a contact, the code accesses the Users[i].accountID property.
string accountID = fields.Users[i].accountID;
Note:
|
|
If you want to take advantage of the functionality offered in the Contact utility class, you can create a Contact object from the account ID returned by the previous code by using the FromName static method.
|
See Also