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?
- Select SharePoint Add-in and provide a name to your app and click on Create.
- You will see the screen below on the app,
- Click on Default.aspx and paste the code below under the,
- “<asp:ContentContentPlaceHolderID="PlaceHolderMain" runat="server">”.
Code:
- <div>
- <b>All Column Data</b>
- <br />
- <select style="height:500px; width:400px" multiple="multiple" id="selectcolumnitems"></select>
- </p>
- </div>
- Now on the navigation click on the App.js file and paste the code below removing the previous code completely.
Code:
- 'use strict';
- var hostweblink;
- var applink;
-
- $(document).ready(function()
- {
- hostweblink = decodeURIComponent(
- getQueryStringParameter("SPHostUrl"));
- applink = decodeURIComponent(
- getQueryStringParameter("SPAppWebUrl"));
-
- var scriptlink = hostweblink + "/_layouts/15/";
- $.getScript(scriptlink + "SP.RequestExecutor.js", loadPage);
- });
-
-
- function getQueryStringParameter(paramval)
- {
- var paramvalue = document.URL.split("?")[1].split("&");
- for (var i = 0; i < paramvalue.length; i = i + 1)
- {
- var Paramval1 = paramvalue[i].split("=");
- if (Paramval1[0] == paramval) return Paramval1[1];
- }
- }
-
- function loadPage()
- {
- getcolumndata();
- }
-
- function getcolumndata()
- {
- var play;
- play = new SP.RequestExecutor(applink);
-
- play.executeAsync
- ({
- url: applink + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('DevData')/items?@target='" + hostweblink + "'",
- method: "GET",
- headers:
- {
- "Accept": "application/json; odata=verbose"
- },
- success: getListdatasuccessful,
- error: getListdatafailure
- });
- }
-
- function getListdatasuccessful(data)
- {
- var jsonObj = JSON.parse(data.body);
- var selectcolumnitems = document.getElementById("selectcolumnitems");
- if (selectcolumnitems.hasChildNodes())
- {
- while (selectcolumnitems.childNodes.length >= 1)
- {
- selectcolumnitems.removeChild(selectcolumnitems.firstChild);
- }
- }
- var result = jsonObj.d.results;
- for (var i = 0; i < result.length; i++)
- {
- var selectOption = document.createElement("option");
- selectOption.value = result[i].Title;
- selectOption.innerText = result[i].Title;
- selectcolumnitems.appendChild(selectOption);
- }
- }
-
- function getListdatafailure(data, errorCode, errorMessage) {
- alert("Not able to get the data, view the error: " + errorMessage);
- }
- Click on the settings icon on the tool on the left.
- Under the properties, select Permissions and provide full control to the app on the Site Collection level.
- Click on the deploy button on the left and run the project.
- Click on the launch button.
- Accept the trust and click on ‘Trust It’.
- Your app will be deployed and open for you as per the following screenshot:
- Your entire items under the Title column appears here as per the SharePoint List.
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: