Survey is showing error - "You have already submitted the response", even when user has not filled the survey yet.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 03:40 AM
Hi Everyone,
We are trying to restrict users from retake survey using this business rule. But the business rule is not working as expected. Could anyone help me understand what might have caused the issue. The screenshot of the issue is attached.
FYI - We are using customized notification for sending out the surveys, which has survey link embedded in the notification content itself.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('asmt_assessment_instance');
gr.addQuery('trigger_id',current.trigger_id);
gr.query();
while(gr.next())
if(gr.trigger_id == current.trigger_id){
{
current.setAbortAction(true);
gs.addErrorMessage("You have already submitted the response.");
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 04:19 AM
Hi Zia,
Can you share business rule configurations?
You are not using before BR right?
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 06:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 08:14 PM
Hello Zia,
There is some syntax error in your code { is missing after while loop. Please check once with below code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('asmt_assessment_instance');
gr.addQuery('trigger_id',current.trigger_id);
gr.query();
while(gr.next()) { // { there was missing
if(gr.trigger_id == current.trigger_id){ //this { is extra you need to remove this
{
current.setAbortAction(true);
gs.addErrorMessage("You have already submitted the response.");
}
}
})(current, previous);
If your issue is not resolved with above code then I believe you need to check the BR script to also check if the existing survey state is complete as shown in below script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("asmt_assessment_instance");
gr.addEncodedQuery("trigger_id=" + current.trigger_id + "^state=complete");
gr.query();
while(gr.next()) {
if(gr.trigger_id == current.trigger_id) {
current.setAbortAction(true);
gs.addErrorMessage("You have already submitted the response.");
}
}
})(current, previous);
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 11:52 PM
Hi Mahendra,
Thanks for your response. I tried both ways you discussed, still the issue isn't resolved.