I'm trying build an array named visitorsIDs[] to get the values for a PeoplePicker in SharePoint API, but no matter who I pick in the peoplePicker, the id's that are sent are always the id's of the 1st person selected in the people picker. Any ideas what I'm doing wrong? I appreciate any help/suggestions...
function resolvePeoplePickers() {
var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePicker_TopSpan;
this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePicker_TopSpan.OnUserResolvedClientScript = function (peoplePickerId, selectedUsersInfo) {
// Get information about all users.
var users = peoplePicker.GetAllUserInfo();
var userInfo = '';
for (var i = 0; i < users.length; i++) {
var user = users[i];
for (var userProperty in user) {
userInfo += userProperty + ': ' + user[userProperty] + '<br>';
}
}
debugger;
var userloginbase = users[0].Key;
var userlogin = userloginbase.split("\\");
var context = SP.ClientContext.get_current();
var newUser = context.get_web().ensureUser(xxxxxxx\\' + userlogin[1]);
context.load(newUser);
context.executeQueryAsync(function () {
//alert(newUser.get_title());
},
function (sender, args) {
//alert(args.get_message());
});
// pause for a second to let the async ensure user complete.
setTimeout(function() {
for (var i = 0; i < users.length; i++) {
getAssignedToUserIdByEmail(users[0].EntityData.Email);
visitorIDs.push(ResolvedToUser.Id);
}
}, 100);
};
Adding this after my original post:
function getAssignedToUserIdByEmail(email) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + '/_api/web/siteusers/getByEmail(%27' + encodeURIComponent(email) + '%27)',
type: "GET",
async: false,
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: (function (data) {
debugger;
if (data.d && data.d.LoginName) {
//alert(data.d.Id);
ResolvedToUser = data.d;
}
}),
error: (function (e) {
alert("Something wrong happened. ");
})
});
}