Showing SCTASK numbers with an email

StewartF
Tera Expert

I'm working on revamping our email notifications, as users don't like them - they show irrelevant information, yet also don't show the right information.

We currently have 3 emails firing to the user when their request is submitted -:

1 - Request REQxxxxxxx has been opened on your behalf
2 - Your Request RITMxxxxxxx has been received
3 - Your request REQxxxxxxx has been approved

I can easily shrink these down to one email, and only have the approved email send when something actually needed approving, instead of when it's auto-approved.

However, I need to also amend the ones we get on the Service Desk - say if a user requests a new starter and kit, we get 11 emails for the individual tasks which is majorly overkill. We have a few steps for both setting up a new starter, and building kit, hence there are so many.

I want to cut this down to just ONE email - I want it to come through as a Request has been logged, providing the RITM number in the subject (easily done, that's fine), but also listing the individual task references in the email body. Links to go to the tasks would be a nicety too.

I've been looking at the mail scripts, and been trying to see if there is a post already on this, but been able to figure it out/find a previous question about it.


Anybody have any ideas how I could achieve this please?

17 REPLIES 17

Andrew Barnes -
ServiceNow Employee
ServiceNow Employee

Greetings Straut,

 You will need to use an email script to query the sc_task table for the records that go with your request. Perform the query in the list view of the sc_task - to find the correct tasks for a given req. Then you take that query and adjust it to use the variables you have available in your mail script (ala current). 

Take a look at the existing email scripts for some inspiration.

It will be something like: 

var scTasks = new GlideRecord('sc_task');
scTasks.addQuery('request', current.sys_id);
scTasks.query();
while(scTasks.next()){
template.print("Task Number: " + scTask.getValue('number'));
}

-Andrew Barnes
Join me at Developer Blog

Hi Andrew,

I'd had a look at some of the standard scripts, and copied the one to show request items, then tweaked with the script you put above. However, it doesn't pull anything through.

template.print("<p></p>" + gs.getMessage("Associated Tasks") + ":<br />");

var scTasks = new GlideRecord('sc_task');
scTasks.addQuery('request', current.sys_id);
scTasks.query();
while(scTasks.next()){
template.print("Task Number: " + scTask.getValue('number'));
}

 

This is the notification template -:

find_real_file.png

and this is what comes through -:

find_real_file.png

 

I'm clearly missing something here - I'm very much a novice when it comes to scripting sadly.

 

That means your 'current' record is on the RITM - not the REQ as you had suggested, just need to tweak your query to use the RITM sys_id vs the Request.

template.print("<p></p>" + gs.getMessage("Associated Tasks") + ":<br />");


var scTasks = new GlideRecord('sc_task');
scTasks.addQuery('req_item', current.sys_id);
scTasks.query();
while(scTasks.next()){
template.print("Task Number: " + scTask.getValue('number'));
}

Something like this? Appreciate the help