Goal
To retrieve the SharePoint Group information of Current User logged in using Javascript.
Solution
- Dowload the "jquery.SPServices-0.6.2.js" file from CodePlex. Save the file somewhere. I save it in "Style Library".
- Use the below given script to get the list of SharePoint Group using javascript.
<!--http://www.jquery.com-->
<script> !window.jQuery && document.write('<script src="http://code.jquery.com/jquery-1.4.2.min.js"><\/script>');</script>
<!--http://spservices.codeplex.com/releases/view/64390-->
<script language="javascript" tye="text/javascript" src="/style library/jquery.SPServices-0.6.2.js"></script>
<!--Custom Script-->
<script language="javascript" tye="text/javascript">
$(document).ready(function () {
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function (xData, Status) {
//Shows the XML returned from the server
alert(xData.responseXML.xml);
//Replace the "<<SHAREPOINT GROUP NAME>>" with your group name will tell that user is on a particular group or not.
if ($(xData.responseXML).find("Group[Name='<<SHAREPOINT GROUP NAME>>']").length == 1) {
alert('User in a group');
}
}
});
});
</script>
This should be it. Happy Coding.