Find User Group in SharePoint 2010 using JQuery

Introduction

This article introduces how to Check user group of sharePoint site in SharePoint 2010 by using spservices.

Procedure

Step 1: Create sharePoint site, create user group and add one user in group.ex: i have added laxman vyavahare in manegement group as in shown below:

 Create User Group

Step 2: Create sharepoint list.

Step 3: Open your Lists NewForm.aspx or EditForm.aspx page by using Sharepoint Designer and pase fallowing code under <script> tag.

  1. <script type="text/javascript" src="../../Js/jquery-1.7.2.min.js"></script>  
  2. <script type="text/javascript" src="../../Js/jquery.SPServices-2013.01.js"></script>  
  3. <script type="text/javascript">  
  4.   
  5. $(document).ready(function () {  
  6.     $().SPServices({   
  7.         operation: "GetGroupCollectionFromUser",   
  8.         userLoginName: $().SPServices.SPGetCurrentUser(),   
  9.         async: false,   
  10.         completefunc: function (xData, Status) {   
  11.             if ($(xData.responseXML).find("Group[Name='Management']").length == 1)  
  12.             {   
  13.                 alert("Management group user Login");   
  14.             }   
  15.             else  
  16.             {   
  17.                 alert("login outside of the Group user");   
  18.             }   
  19.         }   
  20.     }); /*close().SPServices({ */   
  21. }); /* close (document).ready(function() { */  
  22. </script>  
Step 4: Save the NewForm.aspx or EditForm.aspx page , then go to your site and login with user name which you created under group.

Step 5: open your list view and Click on Add new item as in fig.

 

Add New Item

Here you can check group user login....

 Group User Login

Note: You can download latest JQuery for SPServices from http://spservices.codeplex.com.