Display Current Date on a Scheduled Report Using HTML Source Code

CJ43
Kilo Contributor

I want to insert the current or previous date either in the subject or body of a scheduled report. How would I do that using the HTML Source Code? I am an end-user not a developer. 

4 REPLIES 4

Saurabh Gupta
Kilo Patron

Hi,

This can be achieved using mail script within "report_body" field.

 

 

 


Thanks and Regards,

Saurabh Gupta

Thanks, Saurabh for responding to my question. Unfortunately I do not know what script to use or where to place it. I only have access to the source code in the Introductory Message. What script should I use and how should I write if I can use the source code? Thanks again. Your time is much appreciated.

Ron Legters
ServiceNow Employee
ServiceNow Employee

Since you mention you're not a developer, I'm going to add a little more detail for Saurabh's answer. 

There should be record in the 'Scheduled Email Reports' table for your report. In that record, there's a field 'Introductory Message'. You can add mail script to that field using this syntax ${mail_script:<script_name>}. To generate a basic timestamp in system time and system time format the script would be:

var jsTime = new GlideDateTime();
template.print(jsTime);

To create a new mail script, navigate to 'Notification Email Scripts', and click 'New'. Give it a name, which you'll use above in <script_name>, delete all the code that defaults in (your script isn't going to be that complex) and paste in the above.

Add ${mail_script:<script_name>} in the Introductory Message field for Scheduled Report, and you're good.

This will give you the system time in the system format (i.e, '2022-11-22 16:44:45') in the default font, but you can wrap in some CSS to pretty it up. To display it in a different format, check out the docs for GlideDateTime to see how you can change up the script to return different formats.

CJ43
Kilo Contributor

Thanks, Ron for responding to my question. I tried using the scripts mentioned in the source code unfortunately they didn't work. I received an error message "Email script render error: email script does not exist" I am not if I have written it correctly or if I do not have the level of permission to add or modify the source code. Also, I do not see Notification Email Scripts in my view therefore I am assuming I do not have the level of permission to use the Notification Email Scripts. Thanks for your help and time. Much appreciate it.