Click here to Skip to main content
13,253,159 members (50,721 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 3 Dec 2012

SharePoint 2010 State Machine Workflows with Custom Task Forms (InfoPath) using VS 2010 - Part 3 of 3

, 3 Dec 2012
Rate this:
Please Sign up or sign in to vote.
Building Custom SharePoint 2010 Workflow with InfoPath Task Form

Part 1: Building Custom SharePoint 2010 Workflow

Part 2: Configuring and Deploying Custom InfoPath Task Form

Part 3: Sending Data from SharePoint Workflow to InfoPath Form   


In the Part 3 of the tutorial, I will explain the process of sending data from the workflow to the task form (InfoPath). In Part 2 of the tutorial I explained retrieving the data from InfoPath form in the workflow by using the Extended Properties of the Task Properties. We will use the Task Properties object to send the data from our workflow to the InfoPath Form.


To send the data to the InfoPath form we will need a XML file named ItemMetadata.xml. The file ItemMetadata.xml is case-sensitive, so make sure the file name is exactly the same. This file defines the task schema. 

SharePoint pushes the task data to the edit form on load event of the form. We will add the ItemMetadata.xml as secondary data source to our InfoPath form. Irrespective of any use of the ItemMetadata.xml, this file should always be added as the secondary data source. 

Creating the ItemMetadata.xml  

To create the ItemMetadata.xml, in your task editor add the below XML Element.

<z:row xmlns:z="#RowsetSchema"/>

Each property which is to be pushed from the SharePoint Workflow to the InfoPath Form will be added inside the above XML Element.

To add the property, add an attribute starting with ows, then add a '_', followed by the name of the task element. I have defined the content of ItemMetadata.xml as below.

<z:row xmlns:z="#RowsetSchema"





Adding the File as Secondary Data Source 

Open the InfoPath Form in Design mode. In the Data Tab, click on Data Connection Menu. On the Data Connection Dialog box, click on Add to configure the Secondary Data Source.

The next step of the wizard takes in information about the type of the connection. Select the Receive data radio button and click on Next

In next window, Select the XML document radio button, and click on Next

Now browse the ItemMetadata.xml file on the file system, and click on Next

In the Next step, select Include the data as a resource file in the form template, and click Next.

The data connection should be named ItemMetadata. Check the Automatically retrieve data when form is opened check box, and click Finish. Now the ItemMetadata.xml file is embedded as a resource file in the InfoPath form. Hence, ItemMetadata.xml is not required to be deployed with the workflow. I have added the file in the Forms folder of the Workflow just for reference. 

Bind Controls to Task Schema 

On the InfoPath form, drop the controls you want to bind to the task schema. In the sample, I have used text box control to bind the data. To ensure that the task data is not changed, I have made it read-only and change the background color of the text box control to grey.

Right click the control, and click on Text Box Properties. On the Dialog box, select the Data Tab and click the Formula button next to Default Value text box.

On the Insert Formula dialog box, click on Insert a Field or Group. On the Select a Field or Group dialog box, select ItemMetadata connection in Fields drop-down list. Now select the field in that data connection to which you want to data-bind your control, and Click OK. Close all the Dialog boxes by clicking OK


Configuring the Visual Studio Workflow

In the workflow, we will have to pass the data to the InfoPath form in the MethodInvoking event of the Task, i.e. when we are creating the task. We will use the ExtendedProperties dictionary to upload the data to the InfoPath Form. Use the below code to add the values to ExtendedProperties.

if (listItem != null)
                        = listItem["Title"].ToString();
                        = listItem["Technology"].ToString();
                        = listItem["Experience"].ToString();

Deploy the workflow. 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Rupesh Tarwade
Technical Lead
India India
I have been designing and developing systems in .NET since 2006. Started out with .NET 1.1, and progressed through to current version. Started working with SharePoint 2010 in 2011, and am currently gaining experience in SharePoint Online and hosted apps.

You may also be interested in...

Comments and Discussions

QuestionHow to fill in dropdown Pin
Miroslav Mki Cibuľa11-Oct-16 2:08
memberMiroslav Mki Cibuľa11-Oct-16 2:08 
QuestionUpgrade task forms and workflow without stopping running workflows Pin
Anewen14-Apr-15 5:23
memberAnewen14-Apr-15 5:23 
AnswerRe: Upgrade task forms and workflow without stopping running workflows Pin
Rupesh Tarwade20-Apr-15 7:04
memberRupesh Tarwade20-Apr-15 7:04 
GeneralRe: Upgrade task forms and workflow without stopping running workflows Pin
Anewen5-May-15 5:09
memberAnewen5-May-15 5:09 
GeneralRe: Upgrade task forms and workflow without stopping running workflows Pin
Rupesh Tarwade6-May-15 22:32
memberRupesh Tarwade6-May-15 22:32 
GeneralRe: Upgrade task forms and workflow without stopping running workflows Pin
Rupesh Tarwade6-May-15 22:42
memberRupesh Tarwade6-May-15 22:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 3 Dec 2012
Article Copyright 2012 by Rupesh Tarwade
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid