Get SharePoint Group Based On Name 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 name.

Example:

The following code snippet is used to return the group object and its properties from the current SharePoint site’s group collection using PnP JavaScript library, click here to read more.

  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.getByName("My Team Owners").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>