Auto Complete People Picker with current user

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
Lucidica - Jamal
Posts: 7
Joined: Mon May 13, 2013

25 May 2016

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?!

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

26 May 2016

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

User avatar
Lucidica - Jamal
Posts: 7
Joined: Mon May 13, 2013

26 May 2016

Hiya Rostislav

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

Any other suggestions?

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

26 May 2016

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

User avatar
Lucidica - Jamal
Posts: 7
Joined: Mon May 13, 2013

26 May 2016

unfortunately, it still doesn't work! :(

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

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

27 May 2016

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

User avatar
Lucidica - Jamal
Posts: 7
Joined: Mon May 13, 2013

27 May 2016

Hiya Again

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

Thanks for your help!

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 10 guests