How To Get All column Values Of A List Using REST API In SharePoint Online And Office 365

Welcome to an article on “How to get all column values of a list using REST API in SharePoint Online and Office 365” where we will see the steps of creating an app using Napa Tool which will help us to view all the column values of a list using REST API.

  • Open the “NAPA” Office 365 Development Tools through your SharePoint store.

  • Click on Add New Project.

  • It will ask you, what type of app do you want to build?

    build

  • Select SharePoint Add-in and provide a name to your app and click on Create.

    add in

  • You will see the screen below on the app,

    content

  • Click on Default.aspx and paste the code below under the,
    1. “<asp:ContentContentPlaceHolderID="PlaceHolderMain" runat="server">”.  
    Code:
    1. <div>  
    2.     <b>All Column Data</b>  
    3.     <br />  
    4.     <select style="height:500px; width:400px" multiple="multiple" id="selectcolumnitems"></select>  
    5.     </p>  
    6. </div>  
  • Now on the navigation click on the App.js file and paste the code below removing the previous code completely.

    Code:
    1. 'use strict';  
    2. var hostweblink;  
    3. var applink;  
    4. // Load the links on app load  
    5. $(document).ready(function()  
    6. {  
    7.     hostweblink = decodeURIComponent(  
    8.         getQueryStringParameter("SPHostUrl"));  
    9.     applink = decodeURIComponent(  
    10.         getQueryStringParameter("SPAppWebUrl"));  
    11.   
    12.     var scriptlink = hostweblink + "/_layouts/15/";  
    13.     $.getScript(scriptlink + "SP.RequestExecutor.js", loadPage);  
    14. });  
    15.   
    16. //function to retrieve values   
    17. function getQueryStringParameter(paramval)  
    18. {  
    19.     var paramvalue = document.URL.split("?")[1].split("&");  
    20.     for (var i = 0; i < paramvalue.length; i = i + 1)  
    21.     {  
    22.         var Paramval1 = paramvalue[i].split("=");  
    23.         if (Paramval1[0] == paramval) return Paramval1[1];  
    24.     }  
    25. }  
    26. //Function on the app load   
    27. function loadPage()  
    28. {  
    29.     getcolumndata();  
    30. }  
    31. //Retrieve all of the list items  
    32. function getcolumndata()  
    33. {  
    34.     var play;  
    35.     play = new SP.RequestExecutor(applink);  
    36.     //DevData is my list name  
    37.     play.executeAsync  
    38.     ({  
    39.         url: applink + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('DevData')/items?@target='" + hostweblink + "'",  
    40.         method: "GET",  
    41.         headers:  
    42.         {  
    43.             "Accept""application/json; odata=verbose"  
    44.         },  
    45.         success: getListdatasuccessful,  
    46.         error: getListdatafailure  
    47.     });  
    48. }  
    49. //Displays the data under the Title fields of all the items in the list.  
    50. function getListdatasuccessful(data)  
    51. {  
    52.     var jsonObj = JSON.parse(data.body);  
    53.     var selectcolumnitems = document.getElementById("selectcolumnitems");  
    54.     if (selectcolumnitems.hasChildNodes())   
    55.     {  
    56.         while (selectcolumnitems.childNodes.length >= 1)  
    57.         {  
    58.             selectcolumnitems.removeChild(selectcolumnitems.firstChild);  
    59.         }  
    60.     }  
    61.     var result = jsonObj.d.results;  
    62.     for (var i = 0; i < result.length; i++)   
    63.     {  
    64.         var selectOption = document.createElement("option");  
    65.         selectOption.value = result[i].Title;  
    66.         selectOption.innerText = result[i].Title;  
    67.         selectcolumnitems.appendChild(selectOption);  
    68.     }  
    69. }  
    70.   
    71. function getListdatafailure(data, errorCode, errorMessage) {  
    72.     alert("Not able to get the data, view the error: " + errorMessage);  
    73. }  
  • Click on the settings icon on the tool on the left.

    setting

  • Under the properties, select Permissions and provide full control to the app on the Site Collection level.

    Permissions

  • Click on the deploy button on the left and run the project.

    deploy

  • Click on the launch button.

    launch

  • Accept the trust and click on ‘Trust It’.

    Trust It

  • Your app will be deployed and open for you as per the following screenshot:

    open

  • Your entire items under the Title column appears here as per the SharePoint List.

    Title

Here we saw today how to get all column values of a list using REST API in SharePoint Online and Office 365. You will love your app. Keep reading and keep learning!

Keep reading & keep learning!

Read more articles on SharePoint: