Domanda

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

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top