Check Group Properties Using REST API In SharePoint Online And Office 365


Welcome to an article on “How to Check Group Properties using REST API in SharePoint Online and Office 365” where we will see the steps of checking the group properties of a SharePoint group 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?app
  • Select SharePoint Add-in and provide a name to your app and click on Create.click on Create
  • You will see the screen below on the app,Content
  • Click on Default.aspx and paste the code below under the “<asp:ContentContentPlaceHolderID=”PlaceHolderMain” runat=”server”>”.Code:
    1.       Group Properties
    2.       “text” value=“Group Name” id=“grouptextbox” />
    3.       “groupclick”>Check Group Properties
  • 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. varhostweblink;
    3. varapplink;
    4. // Get the links on the page load
    5. $(document).ready(function()
    6. {
    7.     hostweblink = decodeURIComponent(getQueryStringParameter(“SPHostUrl”));
    8.     applink = decodeURIComponent(getQueryStringParameter(“SPAppWebUrl”));
    9.     //Add the click event
    10.     $(“#groupclick”).click(function(event)
    11.     {
    12.         groupdetails();
    13.         event.preventDefault();
    14.     });
    15.     varscriptlink = hostweblink + “/_layouts/15/”;
    16.     $.getScript(scriptlink + “SP.RequestExecutor.js”);
    17. });
    18. functiongetQueryStringParameter(paramToRetrieve)
    19. {
    20.     varparamsval = document.URL.split(“?”)[1].split(“&”);
    21.     for (vari = 0; i < paramsval.length; i = i + 1)
    22.     {
    23.         var param1 = paramsval[i].split(“=”);
    24.         if (param1[0] == paramToRetrieve) return param1[1];
    25.     }
    26. }
    27. // Get the group content
    28. functiongroupdetails()
    29. {
    30.     vargrouptextval = document.getElementById(“grouptextbox”).value;
    31.     var play;
    32.     // Initialize execution
    33.     play = new SP.RequestExecutor(applink);
    34.     play.executeAsync(
    35.     {
    36.         url: applink + “/_api/SP.AppContextSite(@target)/web/sitegroups/getbyname(‘” + grouptextval + “‘)?@target='” + hostweblink + “‘”,
    37.         method: “GET”,
    38.         headers:
    39.         {
    40.             “Accept”“application/json; odata=verbose”
    41.         },
    42.         success: groupexecutedsuccess,
    43.         error: groupexecutedfailure
    44.     });
    45. }
    46.  // Group Executed Completed
    47. functiongroupexecutedsuccess(data)
    48. {
    49.     varjsonObjectval = JSON.parse(data.body);
    50.     varpropertiesval = ‘Group Properties:\n’;
    51.     propertiesval += “Title : “ + jsonObjectval.d.Title + ‘\n’;
    52.     propertiesval += “Description : “ + jsonObjectval.d.Description + ‘\n’;
    53.     propertiesval += “LoginName : “ + jsonObjectval.d.LoginName + ‘\n’;
    54.     propertiesval += “OwnerTitle : “ + jsonObjectval.d.OwnerTitle + ‘\n’;
    55.     alert(propertiesval);
    56. }
    57. // Group Executed Failed
    58. functiongroupexecutedfailure(data, errorCode, errorMessage)
    59. {
    60.     alert(“Error loading properties: “ + errorMessage);
    61. }
  • Click on the settings icon on the tool on the left.settings
  • Under the properties, select Permissions and provide full control to the app on the Site Collection level.select Permissions
  • Click on the deploy button on the left and run the project.run the project
  • Click on the launch button.Click on the launch button
  • Accept the trust and click on ‘Trust It’.Trust It
  • Your app will be deployed and open for you as per the following screenshot:view group
  • Provide the name of the group whom you want to check the properties.
  • Click on ‘Check Group Properties’ and you will find all the details as per screen below of your group.run

Here we saw today how to check Group Properties using REST API in SharePoint Online and Office 365. You will love your app. Keep reading and keep learning!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s