How To: Context item data in InfoPath approval forms

There was a question on the Nintex Connect forum today around form (item) data and showing it on the approval task form. For everyone’s convenience, I’ve copied and pasted it in here.


Nintex Connect, Peter Behler:

“Currently we use a lot of forms, InfoPath forms for forms libraries. Previously I was using webservices to add the Flexi-Task response directly to my forms when an approval is pending. Now that I graduated to Claims based Auth, I no longer have that option. So I’m looking for advice on how other people are handling the situation and giving users the best experience (aka less clicks and screens) Workflow sends an email to approver. Approver opens an email and needs to review/edit the form details before making a decision They click the link to open the item, which opens a web browser and item view/edit. Approver needs to go back to the email, click on the link to make an approval response. Opens another tab or re-opens the browser and it loads the approval screen (Which is not tailored and way too many fields) After making response they close the screen. When I first rolled it out, 90% of the users (who are not fond of computers and want to be at a computer least as possible) mentioned that was a pain in the arse. Open one link to view it and another link to approve it. I may go the lazy approval route so that they use one link to review/edit it, and reply to email to approve.  One less click is faster. I just wish I could find a way to make lazy approval not include the Original Text from the email.”



When working with tasks in Nintex Workflow you have the option to edit the task for in either Nintex Forms or InfoPath. Since the question was around InfoPath, I will focus on InfoPath. This works for both 2010 and 2013. The pictures are taken from a 2010 environment.

NOTE: If you use Nintex Forms, this would be quite easy as there is native integration with the context item and we can easily drag and drop values from the related item onto the approval form.

To allow approvers to view the related form’s data and do the approval in one form, simply follow these steps:

  1. In the workflow designer, open up the task and select Edit Task From -> InfoPath 201x

    This will open InfoPath Designer and allow you to make the following modifications to your form.

  2. Initially the form looks as shown in the screenshot below. We want to keep those options but also add some information about the item, which the workflow is running on. Make it as easy as possible for approvers to review a form and approve at the same time.

  3. From the Data tab in InfoPath select “From SharePoint List”. Go through the wizard and set it up to point to the SharePoint list your form is stored in. Note that the workflow also HAS to run on the same item. I am using a list called “Leave Request”. There is no need to make any changes in the wizard other than on the 3rd screen, select all the data fields you want to show in your approval form. Also, before closing the wizard (second screenshot below) make sure you uncheck the box “Automatically retrieve data when form is opened”. Then finish by clicking ok.

  4. At this stage we have the approval form with a data connection to the SharePoint list hosting our form. The next thing we want to do is filter the SharePoint list items based on the current item’s ID so we only show data of the current item. For that select “Form Load” from the Data tab in InfoPath. We will now setup rules that will first filter the data set of the SharePoint list and then do a query to get the data into the form.

  5. Create a new rule and call it “Set ID”. Then select “Action”

  6. The form contains various data sources already, the two important ones for us are NWContext.xml and the SharePoint list “Leave Request” connection. The first one contains information about the workflow and the items it runs on. One of the fields in this xml is called WorkflowItemID. We will use that to filter the SharePoint list and return only data about the relevant item. The SharePoint list data source will let us filter the result set by using the ID under the queryFields node.

  7. Under Run these actions select Set a fields value, which will open the following screen

  8. Click on the icon next to the “Field” text box and on the next pop up select Show advanced view

  9. In the advanced view you will be able to select your various data sources that are included in the form. Select your list (Leave Requests in my example)

  10. Then expand the tree view and select the ID field under the query

  11. Click OK and then select the formula button on the initial screen. In the formula designer, select Insert Field or Group

  12. On the next screen select Show advanced view as explained in step 8

  13. The we will select NWContext as our data source

  14. Similar to step 11, expand the tree as shown below and select the WorkflowItemID field

  15. Click OK and confirm all open screens

  16. Once you are back on the actual InfoPath Form, in our Set ID rule, locate the Run these actions section, click on Add and select Query for data

  17. In the Query for data pop up, select the SharePoint list data connection (Leave Requests for my example) and click OK. We are all done with the rules now.

  18. The last step is to drag and drop the item fields onto the form. I will use the leave type, start and end date fields just to illustrate the functionality. To drag the fields onto the form, simply click on Show advanced view in the Fields panel. Then select your SharePoint list data source, expand the dataFields node and drag the fields onto your form. Note that I have not considered any formatting or branding in my example to keep it simple for this blog posts sake J

  19. Publish the form, return to the workflow designer, publish your workflow and you are set to go. When a user now opens the task approval form it should look something like this. Approval section on the top, some form information on the bottom:


Tags: , ,

10 Responses to “How To: Context item data in InfoPath approval forms”