How do I dynamically create the Subject in Client Template to populate based on information from the case?

Randy33
Tera Guru

I am trying to dynamically create the subject of a reply email to populate based on information from the case.

I am using the Email [sys_email] table so I'm able to capture the email chain in the reply.

find_real_file.png

I want the case number as well as the short description from the case to be the subject of the email.  The issue I'm having is because the client template isn't using the table used for the case (using sys_email vs sn_hr_core_case_relations).  Could someone point me in the right direction as to how I would accomplish this.

find_real_file.png

8 REPLIES 8

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

To set a field as Subject in a Client Template, you can add ${field_name} to your subject field on Client Template. 

Similarly you can add ${field_name} to the Body HTML field in the Client Template.

For any other information, please refer to this very well done article:

https://community.servicenow.com/community?id=community_blog&sys_id=df609af8dbbbdb405ed4a851ca961928

If I have answered your question, please mark my response as correct and/or helpful.

Thank you very much

Cheers
Alberto

Any update on this?

If I have answered your question, please mark my response as correct.

Thank you very much

Cheers
Alberto

Khushbu Chhapar
Kilo Guru

You can also create Dynamic Subject line by using Notification email script.

There you can Glide the table used for case and then set the subject accordingly.

 

Example : 

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

 

var gr = new GlideRecord('tbl');

gr.addQuery(...);//if any

gr.query();

//write script to get number and filed name.

 

email.setSubject(gr.number +" "+gr.field_name);

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

 

 

 

call the email script in HTML body and empty the subject line of template.

Thank you so much for this information.  Here is what I have so far:

find_real_file.png

And I have added ${mail_script:getSubject} to the body text in the client template to see if I'm getting the case number but doesn't see to be working.  Do you anything wrong with what I have so far?