Names from my SharePoint list are stored with the field names 'People' and 'Responsible', added using a peoplepicker. These fields are of type 'person or group' in SharePoint. In my Service file, I have the following code:
this.getPeople = function () {
var deferred = $.Deferred();
var restQueryUrl = appweburl + "/_api/lists/getByTitle('RisikoAnalyse')/items?$select=People/Title,Responsible/Title&$expand=People/Title,Responsible/Title";
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: restQueryUrl,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data, textStatus, xhr) {
deferred.resolve(JSON.parse(data.body));
},
error: function (xhr, textStatus, errorThrown) {
deferred.reject(JSON.stringify(xhr));
}
});
return deferred;
};
The 'People' field is a multiple value field, while 'Responsible' allows only one value. My controller contains the following code:
$.when(SPService.getPeople())
.done(function (jsonObject) {
angular.forEach(jsonObject.d.results, function (obj) {
$scope.peopleList.push({
people: obj.People.Title,
responsible: obj.Responsible.Title
});
//$scope is not updating so force with this command
if (!$scope.$$phase) {
$scope.$apply();
}
});
});
In this code snippet, I loop through all objects in 'jsonObject.d.results' and add them to the 'peopleList'. The code works for the single value 'Responsible' field but does not handle the multiple values in the 'People' field effectively. I need assistance on how to iterate over the objects inside the 'People' field and include multiple values in my 'peopleList'. Can anyone guide me on how to achieve this effectively?