Current User Display Name

rss

Posted by Stu - Aug 10 ’16 at 08:37

How do you get the current users Display name?

Thanks

Stuart

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 5 years 11 months 29 days
    #1 by Dmitry Kozlov Aug 11 ’16 at 04:54

    Hi Stu,

    Please, use the code:

    SP.SOD.executeOrDelayUntilScriptLoaded((function () { 
        var ctx = new SP.ClientContext.get_current(); 
        var web = ctx.get_web(); 
        ctx.load(web); 
        var user = web.get_currentUser(); 
        user.retrieve(); 
        ctx.executeQueryAsync( 
        function () { 
          alert(user.get_title());
        }); 
    }), "SP.js"); 
    
  • Stu
    Member
    Member for: 3 years 4 months 12 days
    #2 by Stu Aug 11 ’16 at 05:49

    Thanks it worked perfectly

  • GregFitz
    Member
    Member for: 4 years 4 months 16 days
    #3 by GregFitz Oct 3 ’18 at 09:16

    [#1]:

    Hello,

     

    Hope all is well, I have a quick question hoping you can help with.

     

    I wanted to hide a table (or show) based on current user.

     

    Using the following script (thank you Dmitry for forum post) I can get the current user:

     

    SP.SOD.executeOrDelayUntilScriptLoaded((function () {

    var ctx = new SP.ClientContext.get_current();

    var web = ctx.get_web();

    ctx.load(web);

    var user = web.get_currentUser();

    user.retrieve();

    ctx.executeQueryAsync(

    function () {

    alert(user.get_title());

    });

    }), "SP.js");

     

     

    However trying to filter using the above var ‘user’ isn’t working .

     

     

    i.e.

     

    if (user == 'Reviewing%20%Manager') {

    $('.MgmtC').show(); // Enable

    } else {

    $('.MgmtC').hide(); // Disable

    }

     

    I must be missing something

     

    Thanks,
    Greg

     

Displaying 1 to 3 of 3 messages