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.

Scenario

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.”

Solution

 

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:


Enjoy!

Tags: , ,

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

  1. Muna July 28, 2016 at 7:29 AM #

    Thank you for your effort

    i want to ask how to set a feild value in current item
    When the complete task button is clicked ?

    • Patrick Hosch October 18, 2016 at 8:01 AM #

      Similar to the answer below, I’d recommend to use Nintex Workflow to update the list item, rather than InfoPath itself as things like web service calls, etc can go wrong and can be better handled in a workflow

  2. Muna July 28, 2016 at 7:48 AM #

    Another question is I want to submit data via email in infopath
    To a person whos email is stored in a column in the current item , will your way work ?

    Thank you

    • Patrick Hosch October 18, 2016 at 8:00 AM #

      Since this blog post is assuming you have Nintex Workflow, I’d recommend to use a workflow to send the email, rather than InfoPath.

  3. thzu November 17, 2016 at 10:07 AM #

    Hi, thanks for this post!
    I tried using InfoPath and it was alright, but I like the default better. I tried changing it back to default (task content type: Nintex workflow task, Form type: default). But now I get an error when opening the task. Have you tried changing it back to default? Did it work for you?

    • Patrick Hosch March 2, 2017 at 1:17 PM #

      apologies for the delay in getting back to you. i havent tried reverting back yet unfortunately.

  4. thzu November 17, 2016 at 12:51 PM #

    Hi, thanks for this post!
    I tried it and it worked alright, but I like the default forms better. I want to change back to default but I get an error when opening the tasks. Have you tried changing the forms back to default (in review: Task content type: Nintex workflow task, Form type: default). Was is possible to change it back? Because I cannot find a way to get back to normal 🙁

    • Patrick Hosch March 2, 2017 at 1:17 PM #

      apologies for the delay in getting back to you. i havent tried reverting back yet unfortunately.

  5. Wajih November 17, 2016 at 7:08 PM #

    is this possible other way around, like I want to handle all the actions directly from Info Path form. I don’t want to interact with Task Form at all, but want to use Nintex Task List

    • Patrick Hosch March 2, 2017 at 1:23 PM #

      the Nintex task list is just a simple workflow task list SharePoint provides. You can certainly use that. That is where all the tasks are getting stored anyway.

Leave a Reply