how to send survey response of a particular user through mail

thakkallapallay
Tera Contributor

Hi all,

we have this requirement to send survey response of a user to a manager through email.i know responses are saved in metric results table. But where is the form view of response present? If form view is not available can i create it?

Please help me with this.

Thanks,

Ramya

16 REPLIES 16

Inactive_Us2053
Giga Contributor

As far as I know there isn't a form view for task survey responses that looks as 'nice' as the original survey form.   You'll either need to output the details in to a formatted email template as above, or create your own UI Page to display the results of a specific survey in a nice format.   If presentation isn't a worry then I just look at the results as displayed on the task_survey table.


SNOWBeginnner
Kilo Contributor

Hi ,

 

Thanks for posting such useful information.I tried the same to implement the email notification contain Survey Result.

Its working fine for me.Just that I am getting the same email 6times(because i  have 6 survey question).So whenever system is finding any updated value its getting triggered.Could you tell me how i can resolve it?

Notification Created is :

Table Name : asmt_metric_result

When to send : Inserted [checked]

Script name : 

${mail_script:showResponse}

 

Script : showResponse

 

template.print("<p></p>Results:<br />");
template.print("<br> <br />");

var gr = new GlideRecord("asmt_metric_result");

gr.addQuery("instance", current.instance);


gr.query();

while(gr.next()) {
template.print(gr.metric.getDisplayValue() + ": " +gr.string_value + "<br />");


}

 

 

Please help me on ASAP

Did you find any solution to this?

I know this is an old post, but I ran into the same problem.

The reason the notification is being sent more than once (or one per each question) is because the query is running against the asmt_metric_result, and so each time a record is inserted the notification will trigger.

I came across the same issue, to resolve it, I ran the query againts the asmt_assessment_instance table, then I used the asmt_metric_result and got the instance display value. I needed the display value to compare it to the string (number) value from asmt_assessment_instance table.

Now after I found all the matches, I can add them to the email notification based on @meghansmith response from 6 years ago.

Here is the modified script (mail script).

I tested this and it only sends once (even though the survey has 4 questions

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
    var astGR = new GlideRecord("asmt_assessment_instance");
    astGR.addQuery("number", current.number); // this value is a string not a sys_id
    astGR.query();

    if (astGR.next()) {
        var gr = new GlideRecord("asmt_metric_result");
        gr.addQuery("source_id", 'SYS_ID OF SOUCE GOES HERE'); // you can use any other identifer this is just to run the query and filter the records
        gr.query();

        while (gr.next()) {
            var asmtMR = gr.instance.getDisplayValue(); // instance is a reference field, so you want the "display value" not the sys_id to compare to astGR string number
            if (asmtMR == astGR.number) { // compare the string number with the instance display value
                template.print(gr.metric.getDisplayValue() + ":   " + gr.string_value + "<br />"); // this will add each answer to the notification
            }
        }
    }
})(current, template, email, email_action, event);

Output:

find_real_file.png

Hi Nestor. This solution is perfect for my use-case, but I'm confused by this line and I presume that is why I get no results:

 gr.addQuery("source_id", 'SYS_ID OF SOUCE GOES HERE'); // you can use any other identifer this is just to run the query and filter the records