3

I'm trying to populate a PeoplePicker field, using this code:

function testPeoplePicker(){

var ppDiv=$("div[title='PP Field Name']");
var ppEditor=ppDiv.find("[title='PP Field Name']");
var spPPD=SPClientPeoplePicker.SpClientPeoplePickerDict;
console.log(typeof spPPD === "undefined");
var spPP=spPPD[ppDiv[0].id];
ppEditor.val("Lastname, Firstname");
spPP.AddUnresolvedUserFromEditor(true);

}

SP.SOD.executeFunc("/_layouts/15/clientpeoplepicker.js","SP.ClientContext",function(){
        setTimeout(function(){
            testPeoplePicker();
        },2000);
});

However, the typeof spPPD === "undefined" check returns true, indicating that the PeoplePicker dictionary is undefined, and the spPPD[ppDiv[0].id] lookup gives this error:

Unable to get property 
'PPFieldName_0e1071d1-0f13-47dd-957f-1cab4c98c3f2_$ClientPeoplePicker' 
of undefined or null reference

Any idea why I can't access the People Picker dictionary?

5

Make sure the people picker javascript library is loaded. Please try this:

SP.SOD.executeFunc('clientpeoplepicker.js', 'SPClientPeoplePicker', function () {
                //your code goes here
            });
0

I had a similar problem. Variable "PeoplePicker" was undefined and I was receiving error

SPClientPeoplePicker is not defined.

For future readers working sample

$(document).ready(function() {
           SP.SOD.executeFunc("/_layouts/15/clientpeoplepicker.js","SP.ClientContext",function(){
           setTimeout(function(){
           test();
           },2000);
        });


function test(){

            var dispTitle = "People picker title";         
            var pickerDiv = $("[id^='PeoplePickerInternalName'][title='" + dispTitle + "']");


            var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[pickerDiv[0].id];
            peoplePicker.OnUserResolvedClientScript = function GetData(pickerDiv) {

               $("input[id^='field1']").val(peoplePicker.GetAllUserInfo()[0].EntityData.Email);
               $("input[id^='field2']").val(peoplePicker.GetAllUserInfo()[0].DisplayText);

            }

        }
  • Why the two second delay? That shouldn't be necessary. – Oak3 Apr 18 '18 at 8:12
  • He's responding to the initial message, which had the two second delay. – Barry Aug 14 '18 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.