Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting :: How to Retrieve All Groups Using REST API in SharePoint 2013 Root Site ?
Today, we will discuss about How to Retrieve All Groups Using REST API in SharePoint 2013 Root Site. In this example we are using the following method in the NAPA Tool. On your Developer web site, open the “Napa” office 365 Development Tools so select Add New Project. Now Select the App for SharePoint template, name the project produce web site so select the create button. And then replace APP.js with the subsequent source code. After that, publish Your App.
These are important steps to be done before creating the app.
Specify the permissions that your app needs as within the following.
Choose the Properties button at the bottom of the page.
Within the Properties window, select Permissions.
Within the Content category, set the Write permissions for the Tenant scope.
Within the Social category, set the read permissions for the User Profiles scope.
Close the Properties window.
Now, write the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
'use strict'; var hostweburl; var appweburl; // Get the URLs for the app web the host web URL from the query string. $(document).ready(function() { //Get the URI decoded URLs. hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl")); appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl")); // Resources are in URLs in the form: // web_url/_layouts/15/resource // Load the js file and continue to load the page with information about the folders. // SP.RequestExecutor.js to make cross-domain requests $.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js", retrivegroup); }); //Retrieve all of the folders from root Site function retrivegroup() { var executor; // Initialize the RequestExecutor with the app web URL. executor = new SP.RequestExecutor(appweburl); executor.executeAsync({ url: appweburl + "/_api/SP.AppContextSite(@target)/web/sitegroups?@target= '" + hostweburl + "'", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: getGroupsSuccessHandler, error: function(err) { alert("error: " + JSON.stringify(err)); } }); } function getGroupsSuccessHandler(data) { var jsonObject = JSON.parse(data.body); var Groups = document.getElementById("RetriveGroups"); if (Groups.hasChildNodes()) { while (Groups.childNodes.length >= 1) { Groups.removeChild(Groups.firstChild); } } var results = jsonObject.d.results; for (var i = 0; i < results.length; i++) { var allgroups = document.createElement("option"); allgroups.value = results[i].Title; allgroups.innerText = results[i].Title; Groups.appendChild(allgroups); } } //Utilities // Retrieve a query string value. // For production purposes you may want to use a library to handle the query string. function getQueryStringParameter(paramToRetrieve) { var params = document.URL.split("?")[1].split("&"); for (var i = 0; i < params.length; i = i + 1) { var singleParam = params[i].split("="); if (singleParam[0] == paramToRetrieve) return singleParam[1]; } } |
Finally, publish the App and click the Trust it Button shown on the below picture:
Here is the output:
Group Retrieved Successfully.
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options.
Print article | This entry was posted by Peter on June 10, 2015 at 4:59 am, and is filed under European SharePoint 2013 Hosting, European Sharepoint Hosting, European SharePoint Server 2013 Hosting. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |