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.
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.
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.
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.
You can achieve this functionality as follows:
- In SharePoint, create a Tasks list or use an existing one.
- Add a few tasks to the SharePoint Tasks list and assign tasks to different users.
- In InfoPath, create a new (browser-compatible) form template.
- 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.
- 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.
- Double-click the Repeating Table to open its Properties dialog box.
- On the Repeating Table Properties dialog box, click the Display tab, and then click Conditional Formatting.
- On the Conditional Formatting dialog box, click Add.
- 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.
- On the Insert Formula dialog box, click Insert Function.
- On the Insert Function dialog box, select All in the Categories list, select userName in the Functions list, and click OK.
- On the Insert Formula dialog box, click OK.
- On the Conditional Format dialog box, select the Hide this control check box, and click OK.
- On the Conditional Formatting dialog box, click OK.
- On the Repeating Table Properties dialog box, click OK.
- 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.
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 of S.Y.M. Wong-A-Ton. 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, S.Y.M. Wong-A-Ton.