Survey is showing error - "You have already submitted the response", even when user has not filled the survey yet.

zia
Tera Contributor

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);

8 REPLIES 8

Yousaf
Giga Sage

Hi Zia,

Can you share business rule configurations? 

You are not using before BR right?


***Mark Correct or Helpful if it helps.***

zia
Tera Contributor
Yes, using before insert BR.

Mahendra RC
Mega Sage

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

zia
Tera Contributor

Hi Mahendra,

Thanks for your response. I tried both ways you discussed, still the issue isn't resolved.