How to add certain fields in the email script

Gopal14
Tera Contributor

Hi Team,

 

 

How to add certain fields in the email script

 

Gopal14_0-1718097455339.png

 

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Gopal14 

search the email script and add your fields.

what's the challenge?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Community Alums
Not applicable

use template.print(current.fieldname.getDisplayValue());

Pratima Kalamka
Kilo Sage

Hello @Gopal14 

Refer below screenshot here I expanded the caller field and clicked on the  active field to get it.

Caller Active: ${caller_id.active} it will populate automatically. 

1.jpg

If you have specific conditions to get the value then You can try below email script to get the required value

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {


    var ab = new GlideRecord('table_name');
    // ab.addEncodedQuery('add your encoded query here if you have any');
    //ab.addQuery('parent',sys_id); // you can add the reference fileds if it has paent child relationship.ex: //parent, current sysid;
   ab.query();
    while (ab.next()) {
        template.print(ab.field_name); //use this if the target field is string 
        template.print(ab.getDisplayValue('field_name')); //use this if the target field is reference field
    }

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

 

If my answer is helpful please mark it as helpful or correct!!

Pratima.k