- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 01:26 AM
Hi All,
I am trying to show various Incident Task details on an email notification on the Incident table using an email script, the below script is not working -
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Display 3rd party reference and created on from incident task record
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', current.number);
gr.query();
if (gr.next()) {
template.print('Third Party ref' + gr.u_third_party_vendor_reference);
template.print('Created' + gr.sys_created_on);
}
})(current, template, email, email_action, event);
Any help on my script would be much appreciated.
Thank you!
Alex
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 01:46 AM - edited 08-27-2024 01:47 AM
@alex2410 The following should work.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Display 3rd party reference and created on from incident task record
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', current.getValue('sys_id'));
gr.query();
if (gr.next()) {
template.print('Third Party ref' + gr.getValue('u_third_party_vendor_reference'));
template.print('Created' + gr.getValue('sys_created_on'));
}
})(current, template, email, email_action, event);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 01:52 AM
Hi,
In the script current is the Incident record, and you are quering records from the Incident task table.
The relation between these, is that the incident task points to which Incident through the sys_id field.
You are doing a query on the number, which isn't what's stored in that field.
Also, you could have multiple incident tasks that points to the same incident, so you should use a while loop instead of an if-statement in case you get multiple records back.
Replace your query with this, and it should work:
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', current.getUniqueValue());
gr.query();
while (gr.next()) {
template.print('Third Party ref: ' + gr.getValue('u_third_party_vendor_reference'));
template.print('Created: ' + gr.getValue('sys_created_on'));
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 01:29 AM
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Display 3rd party reference and created on from incident task record
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', current.number);
gr.query();
if (gr.next()) {
template.print('Third Party ref' + gr.getValue('u_third_party_vendor_reference'));
template.print('Created' + gr.getValue('sys_created_on'));
}
})(current, template, email, email_action, event);
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 01:41 AM
Hi @Sandeep Rajput , still not working I'm afraid 😞
Mail script still just shows as blank when testing.
Any ideas?
Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 01:46 AM - edited 08-27-2024 01:47 AM
@alex2410 The following should work.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Display 3rd party reference and created on from incident task record
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', current.getValue('sys_id'));
gr.query();
if (gr.next()) {
template.print('Third Party ref' + gr.getValue('u_third_party_vendor_reference'));
template.print('Created' + gr.getValue('sys_created_on'));
}
})(current, template, email, email_action, event);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 03:27 AM
@alex2410 Did this not address your requirement?