Email notification script for Surveys

JonathanJacob
Mega Sage

Hi All,

I am looking to create email notification regarding completed surveys. I have created an event in the registry and a business rule. I am in the process of creating a email notification. I am kind of stuck on how to accomplish list. I have created this mail script (below). In an effort to put my responses on a email with some sort of table with the headers I have created. Any feedback would be great!


<html>
<body>
<strong>Summary of Survey responses:</strong>

<table border="0">
<tr>
<th><b>Number</th></b>
<th><b>Name</th></b>
<th><b>Department</th></b>
<th><b>Phone</th></b>
<th><b>VIP</th></b>
<th><b>Assigned To</th></b>
<th><b>Title</th></b>
<th><b>Overall</th></b>
<th><b>Responsiveness</th></b>
<th><b>Technical Expertise</th></b>
<th><b>Information Provided</th></b>
<th><b>Professional Courtesy</th></b>
<th><b>Comment</th></b>
</tr>


<mail_script>
var gr = new GlideRecord("task_survey_detail");
var sprint = "" ;
//sys id current survey
var current_survey = "" ;
gs.log("sprint=" + sprint);
         gs.log("survey=" + current_survey);
gr.addQuery("instance", current.sys_id);
gr.query();
while(gr.next()) {
gs.log("survey=" + current_survey);
         gs.log("tasknum=" + gr.tsdts_task);
         gs.log("sprint=" + sprint);
         if (current_survey != gr.tsdinst_sys_id) {
         //template.print("<tr>"+ sprint + "</tr>");
         template.print(sprint);
         current_survey = gr.tsdinst_sys_id;
         sprint = '<td>' + gr.tsdts_task + '</td><td>' + gr.tsdinst_taken_by + '</td><td>' + gr.tsdinst_taken_by.department.getDisplayValue() + '</td><td>' + gr.tsdinst_taken_by.phone + '</td><td>'+ gr.tsdinst_taken_by.vip.getDisplayValue() + '</td><td>' + gr.tsdt_assigned_to + '</td><td>' + gr.tsdt_short_description + '</td><td>' + gr.tsdresp_response + '</td>';
       }
       else
       {
       sprint = sprint + '<td>' + gr.tsdresp_response + '</td>';
       }
         //template.print('<tr><td>' + gr.task.number + '</td><td>' + gr.taken_by.name + '</td><td>' + gr.taken_by.department.getDisplayValue() + '</td><td>' + gr.taken_by.phone + '</td><td>'+ gr.taken_by.vip.getDisplayValue() + '</td></tr>' + gr.assigned_to + '</td></tr>' + gr.task.short_description + '</td></tr>' + gr2.response + '</td></tr>');
}
</mail_script>
</table>
</body>
</html>









8 REPLIES 8

in the "Updated" post below I have:



gr.addQuery("tsdinst_sys_created_on", "<=", gs.daysAgo(5));


Do I need to setup an additional glide record query in addition to that?


JonathanJacob
Mega Sage

It seems like I am getting stuck in my else statement. Am I missing something?



*** Script: task_survey=
*** Script: gr.tsdinst_sys_id=11d7fec93ce9e04094299291f8fb973e
*** Script: IF Loop_tasksurvey=
*** Script: IF Loop= tsdinst_sys_id=11d7fec93ce9e04094299291f8fb973e
*** Script: IF Loop_tasksurveySET=11d7fec93ce9e04094299291f8fb973e
*** Script: else Loop_tasksurvey=175453b83cb5e44094299291f8fb9750
*** Script: else Loop= tsdinst_sys_id=175453b83cb5e44094299291f8fb9750
*** Script: else Loop_tasksurvey=22419ae04d981400c9665fe37f7aaa0f
*** Script: else Loop= tsdinst_sys_id=22419ae04d981400c9665fe37f7aaa0f


cwilker10
Giga Expert

Looks like you're on the right track with your debugging efforts. What is returned with this code inside the while loop?

gs.log("survey=" + current_survey);
gs.log("tasknum=" + gr.tsdts_task);
gs.log("sprint=" + sprint);

That will tell you why you're in the else statement, and then can probably tell you where your code is going wrong.


We re-wrote the while loop significantly to transpose the data from rows to columns in a cleaner way that resulted in a much easier object to for-loop the results into rows on the email.

I'll let Jonathan share the final results.