Is it possible to set the subject of an email client template using an email script?

Sue22
Kilo Contributor

I have created a custom email client template in my pdi which uses the London version.

I would like the subject to be set using an email script.

I am able to set the content of the email client template using the following for example:

template.print('hello world');

However, if I try to set the subject of the email client template using the following code in an email script:

email.setSubject('hello world');

This does not set the subject.

I have checked the system log, the email seems to be returning a value of null (please see attached screengrab).

Does anyone have any suggestions of how I would be able to set the subject using an email script? Or is there a known error that anyone is aware of? It is not an option for me to use the subject field provided in the email client template.

Thanks,

Sue

 

11 REPLIES 11

Alexander Grisb
Kilo Guru

You would have to use a mail script to do it, with email.setSubject, unfortunately.

Sue22
Kilo Contributor

Thanks, yes I am using a mail script, however this will not set the subject.

Hey Sue,

 

You are using the correct code: email.setSubject("Hello World");

 

Sometimes the subject won't be set until the email is sent or there may be another issue in your script. I would try making a separate one and trying it.

There may also be an issue with it, but I was able to get it work. The other thing you can do is make a field and call that in the subject and build it through that.

 

Also, the setSubject should not return a value. https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=c_GlideEmailOutboundScopedAPI

 

Sue22
Kilo Contributor

Thanks for your help.

I'll give it another try and see how I get on.