I need to show values from two different lists.There will be 2 column from List1 and another two columns from List2. Two lists are connected with look up column. Please help with JavaScript code for the same.
-
1Can you write the column names and the name of the lookup list so that I can write the full query for you?– Atish Kumar DipongkorCommented Nov 16, 2015 at 6:31
-
List 1 -- Column name: Name, Category List 2- Column name Rating , ID (Nominee ID is lookup with List 1's ID)– Debarun SanaCommented Nov 16, 2015 at 6:35
-
I wrote the query in answer.– Atish Kumar DipongkorCommented Nov 16, 2015 at 6:45
-
You have appeared 1 hr ago but you did not response– Atish Kumar DipongkorCommented Nov 16, 2015 at 12:33
Add a comment
|
1 Answer
Let's say List1
contains following columns
Name, Category
List2
contains
Rating , ID
Column1
is a lookup column in List2
So you have to use $expand
and $select
for getting items
/_api/Web/Lists/GetByTitle('List2')/Items?$select=Rating,List1/Name,List1/Category&$expand=List1
Now make a GET request to get items from two lists
function getItems(url) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + url,
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
console.log(data.d.results);
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
For more explanation you can check my article CRUD Operation to List Using SharePoint 2013 Rest API.