Get SharePoint Group Based On ID Using PnP JavaScript library

PnP-JS-Core library contains the number of extensible methods and properties using which we can achieve various actions in a simple code. To know more about this library component, visit the below links:

Simplified JavaScript Library for SharePoint

PnP-JS-Core Library

SharePoint has lot of building blocks in collections which are used to form a SharePoint site. Those are used in manage the contents, generate reports based on contents & settings, etc.

In this post, we will use the PnP-JS-Core method to get the group information based on ID.

Example

The following code snippet is used to return the group object and its properties based on the group id from the current SharePoint site’s group collection using PnP JavaScript library. click here to read more about different methods methods available to get the SharePoint group.

  1. <!-- Required JS file -->    
  2. <script type="text/javascript" src="/siteassets/scripts/fetch.js"></script>     
  3. <script type="text/javascript" src="/siteassets/scripts/promise.min.js"></script>     
  4. <script type="text/javascript" src="/siteassets/scripts/pnp.min.js"></script>    
  5.     
  6. <div id="sample"></div>    
  7.     
  8. <script type="text/javascript">    
  9. //The below PnP method used to return the group based on name    
  10. $pnp.sp.web.siteGroups.getById(10).get().then(function(result) {    
  11.     document.getElementById('sample').innerHTML = "Title : " + result.Title + " <br/>Description: " + result.Description;    
  12. }).catch(function(err) {    
  13. alert(err);    
  14. });    
  15. </script>
Ebook Download
View all
Learn
View all