Hi All,
I have requirement to show current user group name (site level) when logged into SharePoint 2010 portal.
I used below spservice code to get current user group name,
$(document).ready(function () {
var loggedinUserGroup =””;
$().SPServices({
operation: “GetGroupCollectionFromUser”,
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function (xData, Status) {
$(xData.responseXML).find(“Group”).each(function()
{
loggedinUserGroup = $(this).attr(“Name”);
});
}
}
});
});
Current user has many groups in site collection level. (Ex: GrpA, GrpB, GtrpC and grpD)
In sub site the user was associated with only one group (Ex: GrpC)
My question is, when the user login into the site, it should pick only GrpC from sub site instead it takes the all groups from site-collection level.
Even i used webURL param (webURL: _spPageContextInfo.webServerRelativeUrl) in the above method but the result remains the same
Add two JavaScript file in your Style Library.
<script type=”text/javascript” src=”http:
//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js”></script>
<script type=”text/javascript” src=”http:
//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js”></script>
<script type=”text/javascript”>
$(document).ready(
function
() {
$().SPServices({
operation: “GetGroupCollectionFromUser”,
userLoginName: $().SPServices.SPGetCurrentUser(),
async:
false
,
completefunc:
function
(xData, Status) {
if
($(xData.responseXML).find(“Group[Name=
'Admingroup'
]“).length == 1) {
alert(“login inside of the Group user”);
}
else
{
alert(“login outside of the Group user”);
}
}
});
/*close().SPServices({ */
});
/* close (document).ready(function() { */
</script>
Group1, Group2 and Group3 etc are SharePoint Groups. Replace your group name with this group name and what ever you want to do write your code below of it.
Here I am replacing the URL and redirect the user based on his role. You can also call particular JavaScript function based on user’s group.