none
username() function showing unexpected behaviour

    Question

  • i have one list in sharepoint 2016. In that list i am using one textbox with the function username().

    when in infopath i preview the list the username() function showing only login username in textbox.

    but when i open list in site it is showing username like below

    "i:0#.w|domain\username"

    I want only login user name in text box.

    I already checked other forums Q and Answers on the forum.but no solution.

    when i try to get login user name through "userprofile.asmx" web service.

    it is working well in preview of infopath. but showing below error on list.

    "An error occurred while trying to connect to a Web service"

    kindly reply it immediately.





    • Edited by Jake Conny Monday, April 17, 2017 6:06 AM
    Monday, April 17, 2017 5:00 AM

All replies

  • Hi Basim,

    From your description, you only want to show the user name of the current user in the text box.

    You can use the following formula as the value of the Textbox:

    substring-after(userName(), "\")

    The result is:

    Thanks,

    Wendy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 18, 2017 2:50 AM
    Moderator
  • Dear this is  working thanks.

    but username is "epm admin" and  this  is showing "epmadmin"

    why it is finished space between "epm" and "admin"

    Tuesday, April 18, 2017 5:09 AM
  • Hi Basim,

    I created a user and set his logon name is "domain\epm admin". After that, I opened the form, the textbox showed "epm admin", there is a space between "epm" and "admin".

    Please check the logon name of the problematic user, make sure there is a space in the user name of logon name.

    Thanks,

    Wendy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 18, 2017 6:26 AM
    Moderator
  • Dear if there is space or not but username() function must show what user we created with space  or not.

    i am attaching snapshot of that user.

    Tuesday, April 18, 2017 8:14 AM
  • Hi Jake,

    In SharePoint, UserName is the account name of the user, so, for the user(yourdoamin\epmadmin), it returns epmadmin.

    If you want to return the display name of the user, you need to use userprofile.asmx to get the PreferredName property.

    https://technet.microsoft.com/en-us/library/hh147510.aspx

    In your original post, you said you got an error when using userprofile.asmx, is the LogID of the error 5566?

    If yes, you need to use the Secure Store Service to create a Target Application that contains the credentials for a SharePoint account that has rights to the User Profile Service.

    A similar post about this error(also should work for SharePoint 2016):

    http://blog.tahoepartners.com/index.php/infopath-getuserprofilebyname-web-service-classic-mode-claims-based-authentication-issue-sharepoint-2013/

    Thanks,

    Wendy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, April 20, 2017 2:19 AM
    Moderator