SharePoint out of the box has the Site Users webpart. This web part allows you to connect to a SharePoint group and show the members of that group. If you have enough permissions, you also get a link “add new user” to add new users to the group. Very nice web part to use in collaborative environments. The web part however has one issue. In the screenshot below, you see I configured it to show the members of the ‘'Editors group’.
The webpart shows the members of this group. But when I click the ‘add new user’ link, I end up in the AclInv page, but not in the Editors group. I end up in the first group that is configured in the groups quick launch:
For users this is very confusing, because they probably don’t notice this. If you look in the source of the page, you can see the cause of this problem. The <a> element refers to the correct link, which is AclInv.aspx with a GroupId in the querystring:
href="/_layouts/aclinv.aspx?GroupId=66"
The element also has an OnClick event handler that looks like this:
ONCLICK="javascript:NewItem('\u002ftest\u002ft2\u002f_layouts\u002faclinv.aspx', true);javascript:return false;"
The problem is that this link does not contain the GroupId parameter.
The script below fixes this problem. I added this script to a content editor web part. I know, there are better ways to do this… If you also do it in a content editor web part, make sure that this web part is the last webpart on the page.
<script language="javascript">
function FixAddUserLink()
{
var links = document.getElementsByTagName('a');
for (var i=0; i<links.length; i++)
{
if (links[i].id=='addnew' && links[i].href.indexOf('aclinv.aspx')>0)
{
links[i].onclick = 'javascript:NewItem("' + links[i].href + '", true)';
}
}
}
FixAddUserLink()
</script>
After reloading the page, and clicking the link, I end up in the Add Users page in the group that I expected:
