1

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

2
  • 1
    In this line "visitorIDs.push(ResolvedToUser.Id);". What is ResolveToUser? Where is that getting set?
    – Ray Hogan
    Commented Sep 23, 2019 at 15:54
  • @RayHogan Hi. I added a function to my original post just now. It shows ResolvedToUser = data.d;
    – Susan T.
    Commented Sep 23, 2019 at 16:03

1 Answer 1

1

Can you try changing this line from:

getAssignedToUserIdByEmail(users[0].EntityData.Email);

to

getAssignedToUserIdByEmail(users[i].EntityData.Email);

It looks like it is hardcoded to pass in the first element instead of using i to resolve each user in the loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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