Show SharePoint Survey Friendly message using jQuery

show friendly message survey sharepoint 2013

Once we submit the survey response, still it allows to click on respond survey link but after this, it displays an ugly message.

show friendly message survey sharepoint 2013
show a friendly message survey SharePoint 2013

I had a requirement where the Survey Link was set in tiles web part and we had to display custom message if the survey has been already submitted.

show friendly message survey sharepoint 2013
show a friendly message survey SharePoint 2013

Please find the below code to achieve the requirement. Create .js file and place the code, make sure you change the Tile Div ID according to your client id.



Provide the .js file refernce in the page where Survey link has been provided.

var linkTitle;
var linkOrginal;
var linkMessage;
$(document).ready(function ()
{

SP.SOD.executeFunc(‘sp.js’, ‘SP.ClientContext’, function () {

$(‘a[id^=Tile_WPQ]’).click(function(e) {
linkTitle = $(this).attr(“id”);
//alert(linkTitle);
linkOrginal= $(this).attr(‘href’);
if (linkTitle == “Tile_WPQ10_1_3”)
{
getWebSiteData();
e.preventDefault();
}

});
});

});
var collListItems ;
var currentUser = null;
var web;
var context;
var list;
var viewXml;
var query;
function getWebSiteData() {

context = new SP.ClientContext.get_current();
web = context.get_web();
currentUser = web.get_currentUser();

context.load(web);
context.load(currentUser);
list = web.get_lists().getByTitle(‘Survey’);
var query= new SP.CamlQuery();
query.set_viewXml(‘<View><Query><Where><Eq><FieldRef Name=\’Author\’ LookupId=\’TRUE\’ /><Value Type=\’Integer\’><UserID /></Value></Eq></Where></Query></View>’);

collListItems = list.getItems(query);
context.load(collListItems);
context.executeQueryAsync(
Function.createDelegate(this, this.onSuccessMethod),
Function.createDelegate(this, this.onFailureMethod));
//context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args)
{
var votesCount = this.collListItems.get_count();
if(votesCount > 0)
{
// window.alert(‘You have already voted to this survey.’);
//window.open(this.web.get_url() + ‘/Pages/Survey-Message.aspx’);
//$(‘#WebPartWPQ2’).fadeOut(5000);
window.location.href = this.web.get_url()+ ‘/Pages/Survey-Message.aspx’;

}
else {
// window.open(linkOrginal);
window.location.href=linkOrginal;
}
}

function onFailureMethod(sender, args) {
alert(‘request failed ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());

}


Read some SharePoint online tutorials:

Thanks,
Sambita


You May Also like the Following SharePoint Online Tutorials:

About Sambita Rath

I have 9 years of exprience into SharePoint implementation, architecture, Administrator, development and Training.Designing Information Architecture in SharePoint 2007, 2010,2013 and Office 365.

View all posts by Sambita Rath →

Leave a Reply