Using InfoPath and SharePoint to Create Personalized Views

Systems know who you are, but SharePoint and/or InfoPath solutions rarely take advantage of that awareness.  Here is an easy way to create a more personalized experience for your users using built-in functionality of InfoPath and SharePoint.

This approach will let you create a form that is aware of a user's identity (login name, phone number, display name, etc.) and then allows you to filter a list in SharePoint to only show items that are relevant to them. 

Part 1: Find Out Things About Somebody

The first part requires SharePoint Portal Server unless you want to write your own web service.

§         Create or modify your InfoPath solution. 

§         Make sure that the data source for the form contains all of the fields that you want to store about the user (e.g. DisplayName, WindowsAccount, Title, email, PhoneNumber, etc.).  Make sure you have at least an “alias” field.  This will be the field on which the query is based.

§         Then add a new data connection by selection Data Connections from the Tools menu. 

§         Click Add,

§         choose Receive Data, click Next,

§         choose Web Service, click Next

§         For the URL specify http://[MyPortal]/_vti_bin/UserProfileService.asmx?WSDL where [MyPortal] is the name of your SharePoint Portal Server 2003 instance.

§         Choose GetUserProfileByName, click Next

§         Don’t specify a value for the input parameter, click Next

§         Deselect “Automatically retrieve data when form is opened”, click Finish

 

Now you are ready to query the web service and map return values to values in your form. If you haven’t already laid out your form, do so, and make sure to include the alias form field.    Add a button next to the alias form field.  Double-click on the button to go to its property dialog.  Click on the Rules button.  Set the condition to be when the alias field is not blank.  Add an action to set the value of the secondary data source’s query field to be equal to the value of the alias field.  Add another action for each of the fields you want to map where you set the form field’s value equal to the value of the return set.  Make sure that you store the AccountName return value, this will be the basis of your SharePoint filter.

 

Publish the form solution to a SharePoint Form Library and make sure to promote the fields to SharePoint columns that you want to appear in SharePoint (at least promote the field storing AccountName as this will be the basis of the filter).

Step 2: Filter the List Based On The Current User

As you may already know, SharePoint lists can be filtered to show information based on the current user using the [Me] filter in the list properties.  However, this only works for list columns controlled by SharePoint.  If you want to filter lists based on the current user using information in other columns (e.g. the columns coming from a InfoPath form), this requires a different method.  Based on the information from the Microsoft knowledgebase article, "How to use a URL to pass parameter information with an SQL query for a data source by using FrontPage 2003 and Windows SharePoint Services" you can specify a list to filter on the full domain\username of a user.  By default Current User or UserID uses the friendly version of the username.  Therefore, if you try to filter a list using the WindowsAccount Equals [Current User] approach you will receive an empty list.

Here is the relevant information from the article:

2.                  On the Data menu, click Filter.

3.                  Click Click here to add a new clause.

4.                  Modified Step:  Click the field that you promoted to a column from the InfoPath solution from the Field Name column.

5.                  Click Equals in the Comparison column.

6.                  Click [Current User] in the Value column.

7.                  Click OK.

8.                  In the lower right corner of the edit window, click Code.

9.                  On the Edit menu, click Find.

10.              Type Name="UserID" Location="CAMLVariable" in the Find What box, and then click Find Next.

11.              This will find the following line of HTML code:

 <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>

12.              Change the line of HTML code to the following:

 <ParameterBinding Name="UserID" Location="ServerVariable(LOGON_USER)" DefaultValue="[ LOGON_USER ]"/>

13.              Save the page, and then click Preview at the bottom of the edit window.

Part 3: Validating

§         Fill out a form,

§         specify your own alias,

§         lookup your information using the button,

§         save it to the SharePoint Form Library,

§         do this again only using a different user’s alias,

§         visit the filtered view, and confirm that only your form shows up.

 

If you have any problems or if this process isn't clear, leave a comment.

12 Comments

  • hi there,



    interesting blog entry, almost answered my problem, but could you please expand on:



    1) when you say &quot;Add another action for each of the fields you want to map where you set the form field’s value equal to the value of the return set&quot;, how do I find out what names parts of the name / value pair are available?



    2) is it possible to use this (or any service) to find out who the current user is? That way when someone opens an infopath form, pull their details from sharepoint (name, email address etc...)



    thanks!

  • Don't undestand until I see example.

  • when i do this LOGON_USER is returned as domain\user, is there some other variable that will just return the user without the domain?

  • I am trying to use your method to query the webservice but without any sucess. Where you say
    Add an action to set the value of the secondary data source’s query field to be equal to the value of the alias field
    My tests have shown that the query field is being set but that the result value is not changing.
    Do I need to somehow trigger the query?
    Note that I am relyng on a no code solution

    TIA
    Ian B

  • Hi
    Thanx for the information

    www.codepal.co.in

  • very good blog. But can you tell me the advantages of using infopath for web services?

  • This post could have been done much better if the author had taken the time to completely explain what they meant. The replies based on this post alone explains to the reader that (a) the author was careless in their efforts of providing a complete, specific solution to their reader, and (b) doesn't bother providing the basis for furthur dialog when questions are asked.

    I would also, like to understand what the author means when making reference to "Add another action for each of the fields you want to map where you set the form field’s value equal to the value of the return set. Make sure that you store the AccountName return value, this will be the basis of your SharePoint filter."

    The post is good, but still not 100%. If you take the time to share information for the benefit of providing others a solution, would it not be worthwhile in making a "best effort" to be more thorough? Otherwise, whats the point of taking the time to post it in the first place?

  • What's up, NightHawk?

  • Hi,

    I can follow the connection part (part 1) , but Step 2 I'm lost.
    Item 2 On the Data menu, click Filter.

    What data menu?
    Is this frontpage or infopath?

    help!

  • I have a problem with this solution. If I try to look up an account which does not exist, then I get an Soap Error (UserNotFoundException). The users working with this form will get an error dialog from infopath. Is there a way to handle this exception and validate instead without adding code?

  • Nicely described, Helped me a lott.............

  • Can you please help me in detailed steps for defining rules. Been trying to figure out for many hours now.

Comments have been disabled for this content.