Auto Complete People Picker with current user

rss

Posted by Lucidica - Jamal - May 25 ’16 at 12:24

Hiya Dmitry

Just a quick question to know if there is a way that you can auto complete the people picker with the current logged in user?

I thought that I had seen it before, but I can't seem to find it via search.

Please can you help?!

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 2 days
    #1 by rostislav May 26 ’16 at 06:06

    Hi,

    fd.field('...').value(_spPageContextInfo.userLoginName);
    //if the people picker is in server side render mode, also have to do this:
    fd.field('...').control()._el().find('a:eq(0)').click()
  • Lucidica - Jamal
    Lucidica - Jamal
    Member
    Member for: 4 years 9 months 5 days
    #2 by Lucidica - Jamal May 26 ’16 at 09:30

    Hiya Rostislav

    Unfortunately it didn't work, when i put the _spPageContextInfo.userLoginName in an alert, i just get  "undefined".

    Any other suggestions?

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 2 days
    #3 by rostislav May 26 ’16 at 11:25

    [#2]:

    Try this

    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 () {
                fd.field('...').value(user.get_loginName());
                //for server-side people picker only
                fd.field('...').control()._el().find('a:eq(0)').click();
            });
    }), "SP.js");
    
  • Lucidica - Jamal
    Lucidica - Jamal
    Member
    Member for: 4 years 9 months 5 days
    #4 by Lucidica - Jamal May 26 ’16 at 01:06

    unfortunately, it still doesn't work! :(

    This is on SharePoint Foundation, that doesn't matter does it?

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 2 days
    #5 by rostislav May 27 ’16 at 06:30

    [#4]:

    What is implied exactly by "it doesn't work"? Does the following alert the login?

     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_loginName());
            });
    }), "SP.js");
  • Lucidica - Jamal
    Lucidica - Jamal
    Member
    Member for: 4 years 9 months 5 days
    #6 by Lucidica - Jamal May 27 ’16 at 06:39

    Hiya Again

    Sorry, it seems I made a mistake as now it is working, (the Field name is case sensitive).

    Thanks for your help!

Displaying 1 to 6 of 6 messages