The CreatorCon Call for Content is officially open! Get started here.

Email Script - referencing Incident Task?

alex2410
Tera Contributor

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

 

 

2 ACCEPTED SOLUTIONS

@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);

 

View solution in original post

OlaN
Giga Sage
Giga Sage

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'));
    }

 

View solution in original post

5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@alex2410 

 

(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.

Hi @Sandeep Rajput , still not working I'm afraid 😞

 

Mail script still just shows as blank when testing.

 

Any ideas?

 

Thank you!

@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);

 

@alex2410 Did this not address your requirement?