0

I am trying to retrieve choice values from a lookup field in SharePoint 2013 using REST API.

PFB the code:

$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/GetByTitle('Test')/fields?$filter=EntityPropertyName eq 'Category'",
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: function (data) {
        $scope.choices=data.d.results[0].Choices.results;
         alert();
    },

            error: function (error) {
        alert(JSON.stringify(error));
    }
});  

This works fine for a normal choice field but doesnt work with Lookup field. Any solution?

Thanks, Dheeraj

1 Answer 1

1

Use Expand option to retrieve Lookup column values.

_api/web/lists/getbytitle('project')/items?$select=Client/Name,ClientId,Name,Id&$expand=Client

In above example, Client is lookup column.

Refer this.

2
  • can we remove duplicates from the obtained object?
    – Dheeraj
    Commented Jul 5, 2018 at 5:02
  • Yes, take output field values in array and remove duplicate using javascript OR use jQuery.unique() using jquery. use this link for example stackoverflow.com/questions/9229645/…
    – Anil Pal
    Commented Jul 5, 2018 at 5:08

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.