-1

When User Try To Respond Survey Again ,Displaying Some Error message ,but i want to display A User Friendly Message...

I Read Some Article But Not Found Any Solution Yet,help me

1

You could consider the following solution. Add client side validation to determine whether the user has already responded to survey. If validation will fail then display user friendly message otherwise display the original response form. It will allow to avoid this exception to occur.

Solution

Override JavaScript function for opening response form NewItem2

//override NewItem2 function
var NewItem2 = (function () {
    var NewItem2Orig = NewItem2;

    return function() {
        var evt = arguments[0];
        var url = arguments[1];

        //Read survey for current user to find out if he have already voted   
        readSurveyVotes(function(votesCount){
            //if voted then display custom message 
            if(votesCount > 0) {
                window.alert('You have already voted to this survey.');
            }
            //if not, call original function for opening response form
            else {
                NewItem2Orig(evt, url);
            } 
        });
    };

})();

Reading survey votes for current user

function readSurveyVotes(cbSurveyResult)
{
        var context = new SP.ClientContext.get_current();
        var web = context.get_web();
        var list = web.get_lists().getByTitle("Survey");
        var viewXml = '<View><Where><Eq><FieldRef Name="Author"/><Value Type="Integer"><UserID Type="Integer"/></Value></Eq></Where></View>';
        var query = new SP.CamlQuery();
        query.set_viewXml(viewXml);
        var items = list.getItems(query);
        context.load(items);
        context.add_requestSucceeded(onLoaded);
        context.add_requestFailed(onFailure);
        context.executeQueryAsync();
        function onLoaded() {
            var voteCount = items.get_count();
            cbSurveyResult(voteCount)
        }
        function onFailure() {
            cbSurveyResult(null);
        }
}

Usage

Save the code to JavaScript file and add reference to this file in overview.aspx page, like shown below:

<asp:content contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server">
    <SharePoint:RssLink runat="server"/>
    <SharePoint:CssRegistration runat="server" name="Themable/survey.css">
    </SharePoint:CssRegistration>
    <script type="text/javascript" src="/_layouts/SE/SurveyOps.js"></script>
</asp:content>

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.