Page 1 of 1

Auto Complete People Picker with current user

Posted: 25 May 2016
by Lucidica - Jamal
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?!

Re: Auto Complete People Picker with current user

Posted: 26 May 2016
by rostislav
Hi,

Code: Select all

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()

Re: Auto Complete People Picker with current user

Posted: 26 May 2016
by Lucidica - Jamal
Hiya Rostislav

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

Any other suggestions?

Re: Auto Complete People Picker with current user

Posted: 26 May 2016
by rostislav
Try this

Code: Select all

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");

Re: Auto Complete People Picker with current user

Posted: 26 May 2016
by Lucidica - Jamal
unfortunately, it still doesn't work! :(

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

Re: Auto Complete People Picker with current user

Posted: 27 May 2016
by rostislav
What is implied exactly by "it doesn't work"? Does the following alert the login?

Code: Select all

 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");

Re: Auto Complete People Picker with current user

Posted: 27 May 2016
by Lucidica - Jamal
Hiya Again

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

Thanks for your help!