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

Thanks for the information.

Out of interest, what currently handles all updates and options for survey_instance and survey_response? Mainly after what drives the inserts into the response table..

is it hardcoded in the background?

Thanks
Shaun


Yes, it was. You can view the new include script in demo, it's pretty much the same logic that was previously hardcoded.


CapaJC
ServiceNow Employee
ServiceNow Employee

An easy way to take a risk-free quick look would be to install the plugin in http://demo.service-now.com


hartr
Giga Contributor

Did you find a way to do this - we are on Aspen but it seems whatever I try I cannot get the instance to ignore subsequent duplicate surveys taken by the same person.. It records the additional responses which then invalidates the report data.

I would like it to retain the original responses only for a specific task survey and ignore/abort any attempts at retaking the same survey at a later time.