1

I am retrieving list information using angular js, now while the information is getting looped, for each list item ID, I need to retrieve information from another list where ID is look up column from the first list.

I tried the following code, but am unable to retrieve data from the second list

var myAngApp = angular.module('SharePointAngApp', []);myAngApp.controller('spCustomerController', function ($scope, $http) {

        $http({

            method: 'GET',

            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Questions')/items?$select=ID,Created,Description,Title,Favourites,Author/Title&$expand=Author/Title",

            headers: { "Accept": "application/json;odata=verbose" }

        }).success(function (data, status, headers, config) {
                data.d.results.forEach(function(customer) {

                var id=customer["ID"];
                customer["Description"] = customer["Description"].replace(/<(?:.|\n)*?>/gm, '');
         $http({

            method: 'GET',

            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Answers')/items?$select=QuestionID&$filter=QuestionID eq "+id+"",

            headers: { "Accept": "application/json;odata=verbose" }

        }).success(function (data, status, headers, config) {


            $scope.answers = data.d.results;



        }).error(function (data, status, headers, config) {



        });


        });
            $scope.customers = data.d.results;
        }).error(function (data, status, headers, config) {
        }); 
});
  • You can use $expand operator as the Item Id is looked up with another list – Atish Dipongkor - MVP Sep 26 '16 at 13:01
2

Lookup column information can be retrieved using $expand operator. For example:

List A has column Title, Name and List B has column Title, Name and Lookup column named LookupA (Lookup list is A). So if you are querying in B list, then your query should look like

/_api/web/lists/getbytitle('B')/items?$select=Title,Name,LookupA/Title,LookupA/Name&$expand=LookupA

LookupA will be returned as object

Find more about $expand CRUD Operation to List Using SharePoint 2013 Rest API

Use SharePoint REST Client to test/explore REST API.

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.