Display SharePoint Tasks assigned to the current user in InfoPath

Learn how you can use the userName() function and Conditional Formatting in InfoPath to display only those tasks from a SharePoint Tasks list that have been assigned to the user who has opened the InfoPath form.

ADVERTISEMENTS

While filtering is not supported in InfoPath browser-enabled form templates, you can create an InfoPath SharePoint solution by using Conditional Formatting on InfoPath repeating tables to hide rows based on conditions, and perform custom filtering that way.

Scenario

You have a Tasks list in SharePoint that contains tasks that are assigned to different users. You want to display this SharePoint Tasks list on an InfoPath form, but show only those tasks that are assigned to the user who is currently filling out the InfoPath form.

Solution

Use Conditional Formatting and the userName() function to filter the SharePoint Tasks list, and display only those tasks that have been assigned to the current user.

Discussion

You can achieve this functionality as follows:

  1. In SharePoint, create a Tasks list or use an existing one.
  2. Add a few tasks to the SharePoint Tasks list and assign tasks to different users.
  3. In InfoPath, create a new (browser-compatible) form template.
  4. Add a data connection to the SharePoint list. This will create a secondary data source to the SharePoint Tasks list in InfoPath. Ensure you select the Assigned_To field when creating the data connection. Note: The data of an InfoPath secondary data source is never stored in forms. This means that as soon as you save or submit an InfoPath form and reopen it, the data in the secondary data source will be retrieved as if the InfoPath form is a new form.
  5. On the Data Source task pane, select the secondary data source to the SharePoint list, drag the repeating node for the SharePoint list located under the dataFields node to the InfoPath form template, drop it, and select Repeating Table from the context menu that appears.
  6. Double-click the Repeating Table to open its Properties dialog box.
  7. On the Repeating Table Properties dialog box, click the Display tab, and then click Conditional Formatting.
  8. On the Conditional Formatting dialog box, click Add.
  9. On the Conditional Format dialog box, select Assigned_To from the first drop-down list box, select does not contain from the second drop-down list box, and select Use a formula from the third drop-down list box.
  10. On the Insert Formula dialog box, click Insert Function.
  11. On the Insert Function dialog box, select All in the Categories list, select userName in the Functions list, and click OK.
  12. On the Insert Formula dialog box, click OK.
  13. On the Conditional Format dialog box, select the Hide this control check box, and click OK.
  14. On the Conditional Formatting dialog box, click OK.
  15. On the Repeating Table Properties dialog box, click OK.
  16. Click Preview to test the InfoPath form.

Now as soon as you open the InfoPath form, the tasks in the SharePoint list that have not been assigned to you will be hidden in the repeating table, and you’ll only see the SharePoint tasks that have been assigned to you. This solution also works for InfoPath browser forms.

 


Related Posts

 

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services