1

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.

4
  • 1
    Can you write the column names and the name of the lookup list so that I can write the full query for you? Commented 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) Commented Nov 16, 2015 at 6:35
  • I wrote the query in answer. Commented Nov 16, 2015 at 6:45
  • You have appeared 1 hr ago but you did not response Commented Nov 16, 2015 at 12:33

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.