Including work notes of a closed task in email notification

Eileen Hessmill
Mega Expert

My workflow creates 3 sequential tasks. As each task closes, a notification is sent. I want to include the work note value of the just closed task in the email, but I am getting inconsistent results. The work note from the first task is included in the first notification, but the 2nd and 3rd notifications are including just the work note from the 1st - although I'm getting the 2nd work note in the 2nd email sometimes.

I am using a mail script. Do I need to order the task records to get the correct work note from the latest task?  

This line is in the email body:

${mail_script:zPTC_task_worknote}

This is my Email Script:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,

                  /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,

                  /* Optional GlideRecord */ event) {

var taskRec = new GlideRecord('sc_task');  

taskRec.addQuery('active', false);  

taskRec.addQuery('request_item', current.sys_id);  

taskRec.query();  

 

if(taskRec.next()) {  

        template.print(taskRec.work_notes.getJournalEntry(1));  

}  

})(current, template, email, email_action, event);

Thanks!

1 ACCEPTED SOLUTION

Hi Eileen,



Can you try this in email script and test.



var taskRec = new GlideRecord('sc_task');


taskRec.addQuery('active', false);


taskRec.addQuery('request_item', current.sys_id);


taskRec.orderByDesc("sys_updated_on");


taskRec.query();



if(taskRec.next()) {


        template.print(taskRec.work_notes.getJournalEntry(1));


}






View solution in original post

8 REPLIES 8

I added the orderByDesc right before I received your first answer, and I'm pretty sure it works, although I had it by 'number'.   I took it out because I liked your solution better if it worked. Can you tell me why it doesn't work? Thanks again for getting right back to me. I'll put the email script back in


Hi Gaurav,

This script is great and works well for work notes. The only issue I have is that it will not send the comments if the fulfiller adds a note using Customer Comments. The message will be blank (see screenshot).

 

Is there a away to adapt this script so that it will send either Work Notes or Customer Comments, so that it doesn't matter how the fulfiller adds the comment?

 

Thanks!

John

Gaurav Kumar15
Giga Guru

current.work_notes.getJournalEntry(1) will give you last comment from RITM and not from task as you are triggering notification from RITM table. Because of which, you will have to use mail script.



Thanks,


Gaurav Kumar


Thanks for clearing that up. I updated the correct answer to your second solution.