How to get all choice values from choice field from a SharePoint List using REST API?

Get all choice values from choice field from a SharePoint List using REST API:

Here we going to get all values of a choice field "Country" (Normal Field Not lookup) from SharePoint List Students.
End point "/_api/web/lists/getbytitle('Students')/Fields" gives all the fields details. We are here filtering the Country Field by Title Name (We may also use its internal name) and then calling. Then Using getJSON method we are fetching the values from Country.

$.getJSON(_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Students')/Fields?$filter=Title eq 'Country'", function(res) {
          var allChoices = res.value[0].Choices;
          console.log(allChoices);
 });

OR,

 $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Students')/Fields?$filter=InternalName eq 'Country0'",
        dataType: 'json',
        async: false,
        success: function (data) {
          var allChoices = data.value[0].Choices;
          console.log(allChoices);
        }
  });

Output:
After running it will give values as an array

["Bhutan", "Indonesia", "Russia", "China", "India"]

Comments

Popular posts from this blog

Get list item entity type full name of a SharePoint list using REST API

Get SharePoint list name by GUID

Get Current Web Logged In User of SharePoint Site in jQuery