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
Clark:
Those are ancient versions of both jQuery and SPServices. If you are using those, I *highly* suggest upgrading.
M.
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.
Rajesh, you’re also sort of misunderstanding how SharePoint permissions work. While you may have been asked to do this, it doesn’t really make sense.
Depending how permissions are managed, the current user could have access to content on the current site by being a member of one group – or hundreds. Because of this, there really isn’t a group to display.
M.
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.