Goodbye WhoAmI! Hello userName()
Anyone who's tried to get the username of the person filling out their form in InfoPath 2003 knows the WhoAmI web service. That was the only way to get the username without writing Visual Basic or C# managed code and using System.Environment.UserName.
In InfoPath 2007 we built an easier way.
Announcing a new formula function: userName()
Now you can simply set the default value to the current form-filler's username. No code, no data connections, no custom web service. Just use the formula dialog and select the function from the category "All":
To get a default value like this:
If that's too easy for you, use it in script
If you're writing script anyway, or if you need to check this value as part of a bigger algorithm and don't want to persist the username anywhere in the form, then you can also access this value in script:
Application.User.UserName
Of course, you can also use this in C# or Visual Basic, but you could always use System.Environment.UserName, so that's nothing new.
Either way requires Domain Trust
For security reasons, either approach will make your form require domain trust, so you'll need to publish the form to a shared location (like Windows SharePoint Services) for the function to work.
Enjoy!
-ned
Comments
- Anonymous
November 16, 2006
Kudos to David Gerhardt for covering a scenario around userName in-depth in his blog article: http://blogs.3sharp.com/Blog/davidg/archive/2006/11/14/2380.aspx
- Alex
Anonymous
April 13, 2007
The comment has been removedAnonymous
May 22, 2007
I have my InfoPath 2007 form published to a Sharepoint server with FULL TRUST and keep getting 'system' returned by userName() function. Is there any way to overcome that?Anonymous
January 27, 2008
i was trying to make a form with a field that contain Employee name i found the best way to do so isAnonymous
March 29, 2008
PingBack from http://copyrightrenewalsblog.info/infopath-team-blog-goodbye-whoami-hello-username/Anonymous
June 19, 2008
The comment has been removedAnonymous
June 23, 2008
Hi vishwaswamy, As per the information at the beginning of this post, the "userName()" function is new to InfoPath 2007 - as such, you will not find this in InfoPath 2003. Now, if you stated you were using InfoPath "2003" in error, then this function is available in the UI. Here is a sample for finding the function:
- Add a button to your View
- Add a Rule to the Button
- Add an Action to the Rule as follows: - Action: Set a field'a value - Field: Select the field where you want to set the user - Value: Click the "fx" button - Click Insert Function - Select "All" in the Categories list - Scroll to the bottom of the Functions list and you will see "userName" Scott
Anonymous
July 09, 2008
I have a question about using this function. It works find when the form loads. I however am trying to get the function to recalculate after the same form is opened again later. How does this work? Pease point me in the right direction. Thanks.Anonymous
November 05, 2008
Hi everyone! I am having what seems to be the same issue that by john@thibeaux.com posts about and I am wondering if anyone has a solution. More specifically, I am trying to get the userName() function to recalculate after the same form is opened by another person. The reason this is important in this effort is that we want to use the response to determine user role so that we can do dynamic view switching in InfoPath. Even more specifically - This InfoPath form is expected to be opened, filled out, or later edited using a browser through SharePoint 2007 form Services. Any responses would be appreciated. TIAAnonymous
April 04, 2009
hi I have a problem in this case. I have Used This method but I want that every time someone open the form, it get the new username dynamically. but the form always save the first username it has got. help me pleaseAnonymous
April 06, 2009
The comment has been removedAnonymous
July 29, 2009
The comment has been removedAnonymous
July 29, 2009
Hi Nick, Take a look at this MSDN article as it has the "WhoAmI" web service in there...it's pretty easy to setup: HTTP Security and ASP.NET Web Services http://msdn.microsoft.com/en-us/library/ms996415.aspx ScottAnonymous
July 30, 2009
Thank you Scott I''ll give it a shot. NickAnonymous
July 02, 2010
How can i change the view based on user group, I have three groups User,Team member and manager and three forms based on their requirements.Anonymous
November 10, 2011
email id: could you please help me. im doing project with ns2. my problem is "how to make a node to dead randomly in ns2Anonymous
January 22, 2012
Hi There, How can I get Displayname/Preferred Name out of the username() function. Thanks EricAnonymous
March 29, 2013
From what source does the userName() determine the value? The reason I ask is that we have encountered some cases where it appears that a few users were getting obsolete information. We then add the user to a group under the site collection in which the application is located, and then have the user try again, and the user succeeds. It is as if some users are recognized while others are not. Is there a function that InfoPath could run that would ensure the user would be recognized?