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:
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.
Comments (18)
  1. infopath says:

    Kudos to David Gerhardt for covering a scenario around userName in-depth in his blog article:

    – Alex

  2. sayangh says:

    I have my Infopath 2007 form published to a Sharepoint server and it has been granted domain trust, but still a text-box with default value  userName() shows up blank. Am I doing anything wrong?

  3. Wosiu says:

    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?

  4. Aziz says:

    i was trying to make a form with a field that contain Employee name i found the best way to do so is

  5. vishwaswamy says:

    I am trying to develop an application using infopath 2003.

    but i cant find the above Username() field in my insert function box, is the any other pre-settings to be done?

  6. infopath says:

    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"


  7. says:

    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.

  8. cgk says:

    Hi everyone!

    I am having what seems to be the same issue that by 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. TIA

  9. firouz says:


    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 please

  10. infopath says:

    Hi firouz,

    When using the "userName" function in the default value property as described here, this only changes (i.e. sets the property) when it is blank. If you need to get the user name each time the form is opened, you will need to do these steps:

    1) Remove the "userName" function from the default value property of your text box control

    2) From the Tools menu choose Form Options

        – Select the Open and Save category

        – Click the Rules button

        – Click Add

        – Click Add Action

        – From the "Action" dropdown box choose "Set a field’s value"

        – Click the button next to the "Field" box and select the data source node where you previously had the "userName" function set as the default value

        – Click the "fx" button next to Value, click Insert Function and insert the "userName" function

    What this will now do is fire the "userName" function and set your node each time the form is opened.


  11. Nick H says:

    Goodbye userName()!  Hello WhoAmI? *cry*

    The link at the top of the blog to the WhoAmI web service (tutorial I assume?) is dead.

    Instead of installing Infopath 2007 on everyone’s computers just to allow me to use the userName() function, I wanted to look into using the WhoAmI codeless method for Infopath 2003 (which everyone has installed).  The problem is I cant find any good tutorials as to how to set it up.

    Any links or help is much apprieciated.

  12. infopath says:

    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


  13. Nick H says:

    Thank you Scott I”ll give it a shot.


  14. Sandeep says:

    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.

  15. upender says:

    email id: could you please help me.

    im doing project with ns2.

    my problem is "how to make a node to dead randomly in ns2

  16. Eric Lee says:

    Hi There,

    How can I get Displayname/Preferred Name out of the username() function.



  17. Larry W Virden says:

    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?

Comments are closed.

Skip to main content