When opening a SharePoint EDIT form, I'm trying to capture a people picker value using JavaScript. Unfortunately, the people picker isn't loaded with data when I call .GetAllUserInfo.
I'm using the following line inside $(document).ready(function()...
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', readyFunction);
When readyFunction() runs I get:
GetAllUserUserInfo: object is null or undefined
Basically it looks like I need to slow down the execution of my code until the people picker is fully loaded WITH the value. Waiting for sp.js to be loaded doesn't seem to be the answer. Any ideas? Using setTimeout to call the function works, but it's obviously not an ideal way to have to do it.
Here is the code I expected to work:
$(document).ready(function(){
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', theFunction);
theFunction(){
var dispTitle = "myPpField";
var pickerDiv = $("[id$='ClientPeoplePicker'][title='" + dispTitle + "']");
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[pickerDiv[0].id];
var theUser = peoplePicker.GetAllUserInfo();
var theUserId = theUser[0].EntityData.SPUserID;
alert(theUserId);
}
});