Step 2: Creating the Workflow Task Edit Form

Step 2: Creating the Workflow Task Edit Form

Next, you need to create a form that enables workflow users to interact with the workflow task that is assigned to them.

This step in the walkthrough follows procedures described in How to: Design a Workflow Task Form to Use Task Data.

NoteNote:

This procedure assumes you are familiar with adding controls to an Microsoft Office InfoPath 2007 form and configuring those controls.

  1. Open Microsoft Office InfoPath 2007.

  2. In the Getting Started dialog box, click Design a Form Template.

  3. In the Design a Form Template dialog box, ensure that the Form Template radio button is selected. Select the Blank template, and then click OK.

  4. In the Design Tasks pane, click Controls. Add the following controls to your form:

    Control Type Name Data Type

    Text Box

    Instructions

    Text (string)

    Check Box

    isFinished

    True/False (Boolean)

    Button

    OK

    N/A

    When finished, your form should resemble the following figure.

    Workflow task edit form
  5. Add rules to the OK button.

    1. Right-click the button you added to the form, and then select Button Properties.

    2. In the Button Properties dialog box, on the General tab, click Rules.

    3. In the Rules dialog box, click Add.

    4. In the Rule dialog box, click Add Action, and then click Submit using a data connection. Click Add.

    5. In the Data Connection Wizard, select Create a new connection to and submit data, and then click Next.

    6. Under How do you want to submit your data, select To the hosting environment, such as an ASP.NET page or a hosting application, and then click Next. Click Finish, and then click OK.

    7. Add another rule: On the Rules dialog box, click Add, then click Add Action.

    8. Select Close the Form from the list of predefined actions. Make sure If changes have not been saved, prompt user to save is not selected.

      NoteNote:

      Since this form is used to interact with the workflow, you want to prevent Office InfoPath 2007from prompting the user to save. Leaving it selected could cause exceptions to be thrown during the execution of the workflow

    9. Click OK to exit from the various dialog boxes.

  6. Create a schema file for your workflow task schema.

    Adding the workflow task schema to your form as a secondary data source enables Microsoft Office SharePoint Server 2007 to provide the form with task data, which is used to prepopulate field values after the form is loaded. The first step is to create an XML schema file that represents your workflow task schema. For more information, see How to: Design a Workflow Task Form to Use Task Data.

    1. Using the text editor of your choice, or Visual Studio, create a file named ItemMetadata.xml.

      NoteNote:

      The file name ItemMetadata.xml is case-sensitive.

    2. Add the following element to the file:

      <?xml version=”1.0” encoding=”utf-8”?><z:row xmlns:z="#RowsetSchema" 
      />
      
    3. In the ItemMetadata.xml file, define each task property that you want to use as data in your form. To do this, add the prefix ows_ as an attribute and also add the name of the task property. Set the attribute equal to an empty string.

      In this case, you want to display the instructions that the user entered in the initiation form. Remember that these instructions were added to the workflow task as extended properties when it was created.

      The following code demonstrates how to access the extended property from code.

          private void createTask(object sender, EventArgs e)
          {
            …
            taskProps.ExtendedProperties["instructions"] = instructions;
          }
      

      For this reason, you need to add an attribute for the instructions task property. Your completed ItemMetadata.xml should contain the following text.

      <z:row xmlns:z="#RowsetSchema" 
        ows_instructions="" 
      />
      
    4. Save the finished ItemMetadata.xml file to your hard disk.

  7. Add the workflow task schema to your form as a secondary data source.

    1. In Microsoft Office InfoPath 2007, on the Design Tasks pane, select Data Source, and then click Manage Data Connections.

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

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

    4. Select XML Document, and then click Next.

    5. Browse to the location where you saved your ItemMetadata.xml file, select it, and click Open. Click Next.

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

    7. Enter ItemMetadata.xml as the data connection name, and make sure Automatically retrieve data when form is opened is selected. Click Finish, then click Close.

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

      NoteNote:

      ItemMetadata.xml is required as a secondary data source for task forms. If you do not add ItemMetadata.xml as a secondary data source, the form generates an error when it opens.

  8. Data-bind the Instructions text box control to the instructions elements in the workflow task schema.

    1. Double-click the Instructions text box control.

    2. In the Properties dialog box, on the Data tab, 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 Group dialog box, select your ItemMetadata data connection.

    5. Select the ows_instructions element.

    6. Click OK. On the Insert Formula dialog box, click OK. In the Text Box Properties dialog box, click OK.

      The Instructions text box control is now bound to the instructions workflow task property. When Microsoft Office SharePoint Server 2007 loads your task form, the form displays the task instructions in the text box.

    Notice that we used a Boolean value to add a check box named isFinished to the form. This now becomes an extended property of the workflow task, and is passed to the workflow by Office SharePoint Server 2007. Remember, each time the user edits the task, the workflow code responds to the task change event, and uses this property to determine if the task is complete.

    private void onTaskChanged(object sender, EventArgs e)
    {
        notFinished = 
           !bool.Parse(afterProps.ExtendedProperties["isFinished"].ToString());
    }
    
  9. Set the security level of the form to Domain.

    1. On the Tools menu, click Form Options.

    2. In the Form Options dialog box, in the Category list, click Security and Trust.

    3. Under Security Level, clear the Automatically determine security level check box, and then click Domain.

    4. Click OK to save the changes and close the Form Options dialog box.

  10. Publish the form.

    1. On the File menu, click Save As. In the Save As dialog box, type TaskForm.xsn as the file name. Save the form to the location of your choice. You will browse to this location in future steps in order to add the file as a resource to the workflow project.

    2. On the File menu, click Publish.

    3. In the Publishing Wizard, select To a network location, and then click Next.

    4. Click Browse.

    5. In the Browse dialog box, navigate to the folder where you want to publish the form. Type TaskForm as the file name and then click OK.

    6. In the Publishing Wizard, type TaskForm for the form template name and click Next.

    7. Click Publish, and Close.

Community Additions

ADD
Show:
© 2016 Microsoft