Retrieving User's Email From Group Using JSOM In SharePoint 2013

Introduction

In this article, we will learn how to get a particular group user's properties from the group's basic SharePoint-hosted SharePoint Add-in, using Napa Office 365 development tools. Sharepoint's basic operations are used by JavaScript object model here. If there are any changes, post your comments here.

Develop the project, using the method given below in NAPA tool

  • On your developer site, open Napa Office 365 development tools and then choose Add New Project.
  • Choose the app for SharePoint template, name the project, Create Site and then choose the Create button.
  • Replace APP.js with the source code given below.
  • Publish your app.

Prerequisite

  • The important steps are given below, which are to be followed before creating the app.
  • Specify the permissions that your app needs, as shown below.
  • Choose the Properties button at the bottom of the page.
  • In the Properties Window, choose Permissions.
  • In the Content category, set the Write permissions for the Tenant scope.
  • In the Social category, set the Read permissions for the User Profiles scope.
  • Close the Properties Window.

Basic and important things that we want to know ,

Creating, updating, and deleting the lists through Client Object Model works similarly to Server Object Model using .NET Framework(CSOM,SSOM). .

The operations does not complete until and unless, you call the executeQueryAsync(succeededCallback, failedCallback) function.

SharePoint 2013 introduces a NAPA tool tservice, which is comparable to the existing SharePoint Client Object Model.

NAPA Tool can be used to perform Create, Read, Update and Delete (CRUD) operations from their apps for SharePoint.

 By following this article, you can learn how to create a simple SharePoint-hosted SharePoint Add-in by using NAPA. The add-in that you’ll create includes the controls and the code to manage the lists and list items.

Choose the kind of add-in; you want to create, name the project and then choose the Create button.


NAPA is a tool, which you can use to create SharePoint-hosted SharePoint add-ins.

We can't create a PHA (Provider Hosted APP), using NAPA tool.

Click Create button.


Default .aspx display is like the pic, shown above and App.Js file looks, as shown.

You can add more .js file and add the code to it instead of it to the existing file.


Change your code, which is based on your requirement here.

Default aspx creates a button to start this event.


Change the APP.js file with the code given below.

Now, click settings page to give the permission to this app


Now, publish your app.


Choose the Click here to launch your add-in in a new Window link.


Click Trust it option to deploy your app here, followed by your login popup Window, which will come and ask your credentials.

Enter your credentials and then click OK.




List is deleted successfully.

Here, if you want to delete a list, call the update();function in your code.

default aspx page code 

  1. <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">  
  2.     <div id="starter">    <input type="text" value="List name here" id="ListOperations"/><button id="createlistbutton">ListOperations</button>    <p>    Lists    
  3. </div></asp:Content>   

Source code 

  1. 'use strict';  
  2.   
  3. var context = SP.ClientContext.get_current();  
  4. var user = context.get_web().get_currentUser();  
  5. var web = context.get_web();  
  6. var lists = web.get_lists();  
  7. var listItemCollection;  // This variable is used later when you add list items.  
  8.   
  9. (function () {  
  10.   
  11. // This code runs when the DOM is ready and creates a context object which is   
  12. // needed to use the SharePoint object model.  
  13. $(document).ready(function () {     
  14.       
  15.     $("#createlistbutton").click(function (event) {  
  16.         getuseremail();  
  17.         event.preventDefault();  
  18.     });  
  19.     });    
  20. function getuseremail() {  
  21.   
  22.     var collGroup = context .get_web().get_siteGroups();  
  23.     var oGroup = collGroup.getById(7);  
  24.     this.collUser = oGroup.get_users();  
  25.     context .load(collUser, 'Include(Title, LoginName, Email)');  
  26.   
  27.   
  28.     context .executeQueryAsync(Function.createDelegate(thisthis.onQuerySucceeded), Function.createDelegate(thisthis.onQueryFailed));  
  29. }  
  30.   
  31. function onQuerySucceeded() {  
  32.     var userInfo = '';  
  33.     var userEnumerator = collUser.getEnumerator();  
  34.     while (userEnumerator.moveNext()) {  
  35.         var oUser = userEnumerator.get_current();  
  36.         this.userInfo += '\nUser: ' + oUser.get_title() +   
  37.             '\nEmail: ' + oUser.get_email() +   
  38.             '\vLogin Name: ' + oUser.get_loginName();  
  39.     }  
  40.           
  41.     alert(userInfo);  
  42. }  
  43.   
  44. function onQueryFailed(sender, args) {  
  45.   
  46.     alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());  
  47. }   

Once the code has been executed, go back to SharePoint site and check the list operations, which executed successfully or not.

Thanks for reading the article.