• SharePoint 2016
  • AngularJS 1.5.4


I have a query service that wraps REST calls retrieving data from SharePoint lists. This service works without issue in SP 2013, but it is somehow misbehaving in SP 2016.

Here is the meat of the function I'm calling in the query service.

var promise = $http({
  "headers": { "Accept": "application/json;odata=verbose" },
  "method": "GET",
  "params": {
    "$expand": "Employee",
    "$filter": "PID eq '" + codePid + "'",
    "$orderby": "",
    "$select": "Title,PID,Company,Employee/EMail,Employee/Title"
  "url": _spPageContextInfo.siteServerRelativeUrl + "/_api/web/lists/GetByTitle('" + nameList + "')/items"
}).error(function (data, status) {
  if (data && data.hasOwnProperty("code")) {
    console.error("Error " + data.error.code + " - " + data.error.message.value);
  } else {
    console.error("Error:\t", status);
}).then(function extractResponseArray(response) {
  return response.data.d.results;
return promise;

Here is the code calling that function.

function getDataToDelete(codePid) {
  var promises = {};
  for (var nameList in infoLists) {
    promises[nameList] = qryService.getData(nameList, codePid);
  return $q.all(promises);
function deleteData(responses) {
  var dataCoalesced = [];
  for (var nameList in responses) {
    dataCoalesced = dataCoalesced.concat(
        function getDeletePromise(dataToDelete) {
          return qryService.deleteData(nameList, dataToDelete);
  return $q.all(dataCoalesced);


So, here's the problem. The function calls promptForDeletion and calls getDataToDelete appropriately. In SP 2013, it calls extractResponseArray before it calls deleteData as expected. However, in the SP 2016 environment, it calls deleteData before it calls extractResponseArray and the responses variable passed to deleteData is a promise, not the object expected (either with the promise members or the promise resolutions).

Why are the .then functions getting called out of order?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.