I am experimenting with some Rest API code. My knowledge of javascript and jquery is basic but I know enough to usually get what I need. Usually through trial and error. Here is what I am attempting to do:
- Using "/_api/web/sitegroups/getByName('Intranet Team')/users" to return the ID of all members of that permission group.
- Then run those IDs through "/teams/Sales/_api/web/lists/getbytitle('User Information List')/items(" + items[i].Id + ")" to get the Name, Office and other details for each member of the permission group.
- Lastly print the details of the User Information List into divs by Office location.
The problem I have is on step 3. I am doing something wrong with my conditional and it is returning all users regardless of the location. The following is my sample code:
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getByName('Intranet Team')/users",
type: "GET",
headers: {"accept": "application/json;odata=verbose"},
success: function (data){
var items = data.d.results;
else {
for (var i = 0; i < items.length; i++) {
$.ajax({
url: "/teams/Sales/_api/web/lists/getbytitle('User Information List')/items(" + items[i].Id + ")",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var userOffice = data.d.Office;
console.log(userOffice);
if (userOffice = 'North York') {
$('#NorthYork').append('<h3 class="person">'+data.d.Title+' - '+data.d.Office+'</h3>');
}
},
error: function (data) {
alert(JSON.stringify(data));
}
});
}
}}
Any help would be greatly appreciated. Martin