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.
Thanks its Working.........
ReplyDeleteHello how can i add users who click on a link in sharepoint to a sharepoint group?
ReplyDelete@Anonymous - I think you will have to write a piece of code for add the user to SharePoint Group, this might help you. http://sarangasl.blogspot.in/2009/12/add-user-to-sharepoint-user-group.html
DeleteGr8... It is working ... Thanks
ReplyDeletejust be aware that $().SPServices.SPGetCurrentUser() is itself making an ajax call to fetch the username...
ReplyDeleteI am aware of that fact. Thanks :)
Deleteits not working in Firefox.
ReplyDeleteis there any other solution which will work on all browser??
Not possible the solution produced is tested in all the browsers. Its being used in a live system as well.
DeleteAlthough there is a very big possibility of version.
Thanks,
Maulik Dhorajia
Im not able to find group name in my xml . Kindly advice...Xml is below
ReplyDelete"
"
Cannot see the XML :(
Delete