Wednesday, April 3, 2013

Welcome, First Name Last Name (JQuery Library for SharePoint Web Services)


When a user signs into SP Portal, on the top right hand corner you see name in Format of Last Name, First Name. You could change that by simply using Jquery + SPService (JQuery Library for SharePoint Web Services)

SPService is absolutely phenomenal. It can simply do so much with so little code.

Here is what you need to do to accomplish the desired results.

  • Create a new JS file and link it from your master page.
  • Add a reference to JQuery.SPServices-0.N.N.js to your master page and before your custom .JS File.
  • In the .js file add the following code:

$(document).ready(function() {
    $(".ms-welcomeMenu a.ms-menu-a span").text("Welcome, " + userName);   
        window.userName = "";
   
    var thisUserFirstName = $().SPServices.SPGetCurrentUser({
    fieldName: "FirstName",
    debug: false
    });
   
    var thisUserLastName = $().SPServices.SPGetCurrentUser({
    fieldName: "LastName",
    debug: false
    });

    window.userName = thisUserFirstName + " " + thisUserLastName;
}

Once this code has been put in place, when a user sign in to SP, they will see Welcome, First Name + " " + LastName on the right hand top corner.

1 comment:

  1. Help! I'm trying to do the same but took the user name and put it in a display in the body where it renders on the DOM as displayName ("LastName, FirstName") to display as "FirstName LastName". I need help. I have searched and searched and no luck. Your article comes close. Please help.

    ReplyDelete