Preventing duplicate entries for Surveys

soelofsen
Kilo Explorer

Hi guys,

The requirement is to ensure that a survey cannot be taken twice on the same survey by the same person, thus preventing duplicates in the survey instances.

There is a business rule that queries the survey_instance table, and checks against the taken_by field, and also the Incident number field.
If an entry is found, the operation is meant to abort.

This does not appear to be working correctly. Even with this script, duplicate entries can be created.

The script thats meant to prevent the duplicates looks as follows:

var gr = new GlideRecord("survey_instance");
gr.addQuery("taken_by", current.taken_by);
gr.addQuery("u_task_number", current.u_task_number);
gs.log("taken_by: " + current.taken_by);
gs.log("u_task_number: " + current.u_task_number);
gr.query();
if (gr.next()) {
gs.log("FOUND");
gs.log("You have already submitted a survey for this ticket. Aborting the operation");
current.setAbortAction(true);
}

There is also a script that runs when the instance is created that sets the incident number to the survey instance.

My question is.. When is the preventing script meant to run, so as to not create the instance when an entry is found..

This functionality is very confusing, and really doesnt appear to work.

Please assist where possible.

Thanks
Shaun

8 REPLIES 8

sylvain_hauser
Tera Contributor

If I remember well, there is an option at survey level to avoid duplicates. If the user answer a second time the survey, the last answer is kept I think.

I can find that on the wiki:
http://wiki.service-now.com/index.php?title=Creating_a_Survey#Updating_survey_responses_versus_creating_a_new_set_of_responses

Does it answer your needs?


HI Sylvain,

Im afraid this does not.. The reason being is if I take a survey on an incident, I would like those details kept. However, if i try and take the survey again for that same incident, I dont want a new entry to be created, or for my first survey to be overwritten.

Thanks
SHaun


CapaJC
ServiceNow Employee
ServiceNow Employee

The new Best Practices - Task Survey plugin will do what you describe. Available in Spring 2009 Stable 1 released just Friday. Check out the wiki where this plugin is described.


Also with Stable 1 we move most of the survey logic to a Script Include called 'SurveyProcessor'. This is where we handle the update options for survey_instance and survey_response.