I'm trying to attach a script to a list page in order to hide a column depending on the user's permissions.
This is the code I put on the aspx using SharePoint Designer 2010:
<asp:Content ContentPlaceHolderId="ScriptHideColumn" runat="server">
<SharePoint:ScriptLink runat="server" Localizable="false"
name="/SiteAssets/_scriptEscondercolumna.js" id="ScriptHideColumn1" />
</asp:Content>
And this is the error I get:
Error An unexpected error has occurred. Troubleshoot issues with Microsoft SharePoint Foundation. Correlation ID: 308118dd-5e8c-419e-9855-cc5be7810518 Date and Time: 11/04/2018 09:01:29 Go back to site
How can I make the script work without getting any errors?
This is the javascript code:
// JavaScript source code
function checkUserGroup() {
bool isMember = false;
SPSecurity.RunWithElevatedPrivileges(delegate
{
using(SPSite site = new
SPSite(".../test_")) {
SPWeb web = site.RootWeb;
string groupName = "Test_ Visitors";
var spGroup = web.Groups[groupName];
isMember = web.IsCurrentUserMemberOfGroup(spGroup.ID);
}
});
return isMember;
}
function hideColumn() {
var isVisitor = checkUserGroup();
if (isVisitor) {
document.getElementsByName("columnHide")[0].style.display = none;
}
}