How to Customize/Replace the “You are not allowed to respond again to this Survey” SharePoint 2010 Survey Message

Referred Link - http://sharepointdrive.blogspot.sg/2013/04/how-to-customizereplace-you-are-not.html



Survey Questions can be easily created on SharePoint 2010, where it is often required that no user fills the Survey twice. This can be easily achieved in OOB (Out of Box) fashion.

But the problem is that user sees the error message like the one shown below (Pic 1) which will definitely not look good on your Site and there is no easy way to change this.

There are many ways to fix this issue but the approach which i applied was on the client side Ecmascript method. As shown in the image on left we will be performing the following tasks.

  • Create a Link to Survey Question.
  • Include a CEWP on the page where the image having link to survey question will be shown.
  • The code in CEWP will checks if user has responded to survey earlier
  • Based on response Show either "Thanks for feedback :Image 2" or "Fill the Feedback: Image 1"
Ok so before we start this was the Error message we get if a user tries to fill the Survey again.(OOB way) but we dont want this screen to appear
How to get the Link to Survey Questions
  • Open the Survey List and get the code for replying to survey as shown below
  • Copy the code in a Notepad file. This will be looking somewhat like the below code.
?
1
2
<a accesskey="N" href="javascript:__doPostBack('ctl00$SPWebPartManager1$g_b76d52da_a06c_ 4545_bcb8_5f1ca8bddb99$ctl01$ctl0$toolBarTbl$RptControls$ctl00$diidIONewItem','');" id="someLonggggggggggId" onclick="javascript:NewItem2(event,'\u002f_layouts\u002flistform.aspx?ListId=\u00257B69901B7A\u00252DEE5C\u00252D4A24\u00252D9EF2\u00252DD3B39B5B4AE8\u00257D\
u0026PageType=8');return false;" title="Respond to this Survey"></a>
  • Now add the CEWP to the page where you want the user to click on the Image to Fill up the Survey. I have shown the below image as the link to survey in my example.
  • The image we will be showing after the user fills up the survey is (This image will not have any hyperlink)
  • So to do this transition we will put the below code in the CEWP
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
 
 
<script language="javascript" type="text/javascript">
    var namedListItem;
    var context = null;
    var web = null;
    var currentUser = null;
    var Author1 = null;
    var Author2 = null;
    var productcollection;
 
 
    $(document).ready(function () {
        ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js");
    });
 
   
    function getWebUserData() {
        context = new SP.ClientContext.get_current();
        web = context.get_web();
        currentUser = web.get_currentUser();
        currentUser.retrieve();
        context.load(web);
        context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
    }
 
   
    function onSuccessMethod(sender, args) {
            var userObject = web.get_currentUser();
            Author1 = userObject.get_title();
            Author2 = userObject.get_loginName()
            checkUserPresent();
      }
 
    function onFailureMethod(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
               }
 
    
    function checkUserPresent() {
            var list = web.get_lists().getByTitle('FY12 ISD Staff Event');
            var query = "<View><Query><Where><Eq><FieldRef Name='Author'/><Value Type='User'>" + Author1 + "</Value></Eq></Where></Query></View>";
            var camlQuery = new SP.CamlQuery();
            camlQuery.set_viewXml(query);
            this.productcollection = list.getItems(camlQuery);
            context.load(this.productcollection);
            context.executeQueryAsync(Function.createDelegate(this, this.productsReceived), Function.createDelegate(this, this.failed));
         }
 
    
    function productsReceived() {
        var count = 0;
        var listEnumerator = this.productcollection.getEnumerator();
        //iterate though all of the items
        while (listEnumerator.moveNext()) {
            count = count + 1;
        }
        if (count == 1) {
            document.getElementById("demo").innerHTML = "<img class='ms-rteImage-1 ms-rtePosition-1' alt='Thanks for feedback' src='/PublishingImages/Team32.bmp'/>";
        }
    }
 
 
 function failed(sender, args) {
 
 }
</script>
 
 
<p id="demo">
<a title="Respond to this Survey" id="A1" accesskey="N" onclick="javascript:NewItem2(event,'\u002f_layouts\u002flistform.aspx?ListId=\u00257B69901B7A\u00252DEE5C\u00252D4A24\u00252D9EF2\u00252DD3B39B5B4AE8\u00257D\u0026PageType=8');return false;" href="javascript:__doPostBack('ctl00$SPWebPartManager1$g_b76d52da_a06c_4545_bcb8_5f1ca8bddb99$ctl01$ctl00$toolBarTbl$RptControls$ctl00$diidIONewItem','');">
    <img class="ms-rteImage-1 ms-rtePosition-1" alt="Budget Submission" src="/PublishingImages/Team32.bmp"></a></p>
So we will now never get the error message that the user has not registered becuse if the user is already registered then we will not show the hyperlink to the survey questions..

You May Also Like

0 comments