Thursday, July 26, 2018

Make all SharePoint Surveys truly anonymous real quick

If you have worked withe surveys, you must be knowing survey provide an option "Show user names in survey results", to make survey anonymous, If not you could refer this. Now the problem with this is anyone with rights to edit list settings could change this setting and all users would be visible. 

There is no suggested approach to do this there are lots of options available. One very nice article is available on this msdn blog. Mostly suggested changing the name using event receiver or workflows. But none of these serve my purpose, as i needed to make all the surveys on the farm anonymous including the new ones. Also with hundreds of surveys across the farm, these workflows or event receivers could hamper performance.
So, i did a small trick to make sure no one to change the list setting and rest SharePoint could handle automatically.
I made some tweaking in the application page witch impacted all my surveys. We could also do the same for a particular site.
We will have to make changes in two application pages, available in layouts folder of 15 hive. Combined these changes will give an effect to of no in survey setting.
  1. ListGeneralSettings.aspx : This page opens when we click "ListName, Description, Navigation in site settings.
  1. New.aspx : This page opens when we create a new survey list. Page URL is same for both popup and advanced options page.
  1. To make sure user can not select yes on advanced options screen. To do this find the below ts tag and comment it.
  1. <td class="ms-authoringcontrols" nowrap="nowrap"><input id="onetidShowUserNamesNo" type="radio" value="on"  name="showUsernames" title="<SharePoint:EncodedLiteral runat='server' text='<%$Resources:wss,lstsetng_showusernamesyes_title%>' EncodeMethod='HtmlEncode'/>" /><label for="onetidShowUserNamesYes"><SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,lstsetng_showusernamesyes_label%>" EncodeMethod='HtmlEncode'/></label></td>
  1. By pass the Basic creation popup and navigate to advanced screen because by default SharePoint consider it yes. To do this:
  1. Find the below code in the file:
x





ListGeneralSettings:
Search for "Survey Settings" and make radio button with id "RADShowUserYes" hidden by adding attribute visible:false. This will hide the yes option in List settings.

New.aspx: We will make two changes in this file.
if (this.IsDialogMode){
    %><a class="ms-textSmall" href="javascript:;" onclick="NavigateToFullPage()"><SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,lstsetng_advancedoptions_text%>" EncodeMethod='HtmlEncode'/></a><%}

    and another if condition inside this if. Final code should look like this:

    if (this.IsDialogMode)
    {
    if (HttpContext.Current.Request.Url.AbsoluteUri.Contains("ListTemplate=102"))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "NavigateToFullPage()", true);
            }else { 
    %>
    <a class="ms-textSmall" href="javascript:;" onclick="NavigateToFullPage()"><SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,lstsetng_advancedoptions_text%>" EncodeMethod='HtmlEncode'/></a>
    <%
            }}

    If you have any existing survey lists, you could use powershell to to change their list setting.

    No comments:

    Post a Comment

    If you liked the post, please share it.
    Subscribe to your email and receive new articles on your email