Skip to main content

Cloud

SharePoint 2010: Getting User Information in InfoPath Form Services

Situation

So you’ve got this nice InfoPath form, and you want to pre-populate it with user information. This means you’ll need to somehow get the user’s login information into the InfoPath form. Unfortunately, there’s no simple or straightforward way to do this.
Several blogs reference just calling the form’s User property and everything magically works in SharePoint. I can tell you from personal experience that this isn’t the case. There are other blogs saying to use a new field in the form that has its Default Value set to InfoPath’s userName() function. This also doesn’t work, at least not completely.

Solution

So what do you do to get user information for the current user within an InfoPath form? You use a combination of the above techniques. That might seem easy, but it has its tricks, which I’ll cover when we get to that point.
The first point I want to make is that you must use code-behind to access and manipulate user information in InfoPath Form Services. It cannot be done from the InfoPath designer because the binding of the User property doesn’t happen in time.

Create a Field Called UserName

The first thing you need to do is create a Text field on your form that has its Default Value set to userName(). I named my field UserName to avoid confusion. userName is an InfoPath function that binds user data to the InfoPath form. It’s technically supposed to populate this field with the user name, but it doesn’t. It does populate the User property of the form. Interestingly enough, the User property is populated on Form_Load only if the call to userName() is made. Otherwise, User is null.
image

 

Use the Form’s User Property

This User property isn’t very useful. It only contains a UserName and LoginName property, which are both strings.
However, LoginName can be used in conjunction with your login provider to convert the LoginName to something useful. You can also use it to pull back more data about the user from a membership provider or SharePoint itself. That information will allow you to continue populating your form with relevant data.
So there you have a way to get the current user’s login information in InfoPath that will work in InfoPath Forms Services on SharePoint. Not particularly difficult, but definitely convoluted. Moreover, you have to be ok with deploying code behind for your forms.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Andrew Schwenker

Andrew Schwenker is a Sr. Technical Consultant within Perficient’s Microsoft National Business Unit East's SharePoint practice. Andrew has nearly 2 years of experience in consulting and has participated in projects that have touched nearly every aspect of SharePoint 2010. Andrew earned his Bachelor’s degree in Computer Science as well as Master’s degrees in Computer Science and Information Systems from Indiana University. He’s interested in creating winning solutions to generate business innovation using SharePoint. Prior to starting at Perficient, Andrew completed internships with General Electric, ExactTarget, and Great American Financial Resources. During his studies, he actively participated in Alpha Phi Omega National Service Fraternity and competed in the first annual Cluster Challenge at SC07 in Reno, NV. Andrew was a part of the dynamic PointBridge team that was acquired by Perficient.

More from this Author

Follow Us
TwitterLinkedinFacebookYoutubeInstagram