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
This is because GetGroupCollectionFromUser does not examine whether the group has access to the sub-site. It only enumerates the groups which the user belongs to. The method works correctly; it just doesn’t do what you think it’d do.
What you could do is to iterate through the groups and check whether they have permissions in the sub-site.