[MSDN]How to: Design a Workflow Task Form to Use Task Data

Published: May 2010

When Microsoft SharePoint Server 2010 displays a custom Microsoft Office InfoPath 2007 form for a workflow task, SharePoint Server 2010 passes the task data to the form as XML. For your InfoPath task form to be able to understand and parse the task data XML, you must add the task schema to the form as a secondary data source.

To do this, you must create a file called ItemMetadata.xml that represents the task schema, and then add that file to your form as a secondary data source. Then you can data-bind your form controls to specific elements of the task schema XML.

Note

SharePoint Server 2010 always sends the task data XML to the task edit form on load. Because of this, you must always add an ItemMetadata.xml file to your form as a secondary data source, even if you do not plan on using any of the task data. Otherwise, SharePoint Server 2010 generates an error.

To create a schema file for a workflow task schema

  1. In the text editor of your choice, create a file named ItemMetadata.xml.

Note

The file name ItemMetadata.xml is case-sensitive.

  1. Add the following element to the file:

    <z:row xmlns:z="#RowsetSchema"/>
    
    
  2. In the file, define each task property that you want to use in your form. To do this, add an attribute composed of the prefix ows and the name of the task field. Set the attribute equal to an empty string.

    For example, suppose there are two task fields you want to use in your form: instructions, and comments. Your finished ItemMetadata.xml file would contain the following:

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

Note

You must define an ows attribute for each task field in your form from which you want to retrieve data, even standard task fields that are included on all tasks, such as Title or Assigned To.

You do not need to define attributes for any task fields in your form from which you do not want to retrieve data.

  1. Save the finished ItemMetadata.xml file to your hard disk.

To add the task schema to a workflow form as a secondary data source

  1. In Microsoft InfoPath 2010, under Design Tasks, select Data Source, and then click Manage Data Connection.

  2. On the Data Connections dialog box, click Add.

  3. In the Data Connection Wizard, select Add a new connection to, and Receive data. Click Next.

  4. Select XML Document. Browse to the location where you saved your ItemMetadata.xml file, select it, and then click Next.

  5. Select Include the data as a resource file in the form template, and then click OK.

  6. Enter ItemMetadata as the data connection name, and make sure Automatically retrieve data when form is opened is selected. ClickFinish.

    After you include the ItemMetadata.xml file as a resource file in the form template, you no longer need the ItemMetadata.xml file itself. You do not need to include the file in your workflow solution.

To data-bind your form controls to the task schema

  1. In InfoPath 2010, double-click the control on your form that you want to data-bind.

  2. In the Propertiesdialog box, on the Datatab, under Default Value, click the formula button.

  3. In the Insert Formula dialog box, click Insert a Field or Group.

  4. In the Select a Field or Groupdialog box, select your ItemMetadata data connection, and then select the field in that data connection to which you want to data-bind your control. Click OK.

  5. In the Insert Formuladialog box, click OK. In the Properties dialog box, click OK.

    For more information about data-binding form controls to data sources, see the InfoPath 2010 help.

你可能感兴趣的:(workflow)