2

I run a query with REST over two lists. List1 is connected through the field Country with List2.

In the console, I can read the data from the second List but I can't seem to extract it from data.d.results.

success: function (data) {
    var items = data.d.results;
    for(var i = 0; i < items.length;i++) {
    message += items[i].Date_x0020_of_x0020_Event + items[i].Column2 + ' <br />';                             
   console.log(items[i].Title);
               }
   $("#div1").html(message);
        console.log(data.d.results);
    },

Column2 is the field in List2 connected with Country from List1. It's not retrieving anything there.

console after query

2

To extract data.d.results you can use for loop as the following:

for (var i = 0; i < data.d.results.length; i++) 
    {  
     var item = data.d.results[i];  
         console.log(item.Title);
    } 

For more details Check


[Update]

Consider, you have two lists:

  • List1.
    • Col1.
  • List2.
    • ColA.
    • LookupField to List1.Col1

So to query List 2 use the below endpoint

 /_api/web/lists/GetByTitle('List2')/items?$select=ColA,LookupField/Col1$expand=LookupField 

To read it use

 item.LookupField.Col1
  • Thanks for the comment, The Title is easy to get, it's the column2 in the second List. I think I can retrieve with this: html += "<tr><td>" + item.Title + "</td><td>" + item.EmployeeName + "</td><td>" + item.Salary + "</td><td>" + item.Dept.Title + "</td><td>" + item.Dept.Code + "</td></tr>"; I guess I have to call item.Listname.Field – Marco Nov 6 '17 at 18:54
  • You should use item.LookupField.Col1 , Please Check the updated answer – Mohamed El-Qassas MVP Nov 6 '17 at 19:21
  • Hi Mohammed, yes I checked your link and I saw it's item.Lookupfield.col1 Cheerz – Marco Nov 6 '17 at 19:58
  • @Marco Please don't forget to Mark the answer as accepted in case it helped you :) Thanks! – Mohamed El-Qassas MVP Nov 6 '17 at 19:59

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.