0

I have an array with a few user email addresses in it, trying to iterate through the array and get Ids. Console log is telling me xuser is undefined.

When I manually enter the url below into the browser with an email from the array I get the desired xml result, with users id.

EmailArray.forEach(GetUserId);

function GetUserId(item) {

  console.log(item);
  $.ajax({ 
    url: xhost + "/portal/_api/web/SiteUsers?$select=Id&$filter=Email eq '" + item + "'",
    type: "GET", headers: { "Accept": "application/json;odata=verbose", },
    success: function (data) {
      var xuser = data.d.Id;
      console.log(xuser);
    },
    error: function (error) { alert(JSON.stringify(error)); }
  });
}

Suggestions?

1
  • figured it out literally 30 seconds after posting, will mark as answer after 24 hrs...
    – BDC604
    May 22 '19 at 20:19
1

Changing as below returned desired results.

var xuser = data.d.results[0].Id;

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.