- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 11:39 AM - edited 01-31-2023 07:14 AM
I am creating a document script to insert current date in "January 23, 2023" format. I have created the following document script and called within the HTML template ${template_script:CurrentDate}. However, I am receiving null when previewing the document. Any advice on where I have gone wrong?
(function runTemplateScript(target /*GlideRecord for target task*/ ) {
//Add your code here to return the dynamic content for template
var cd = new GlideDate();
cd.getByFormat("MMMM D, YYYY");
template.print(cd);
})(target);
Note: I am working in a Human Resources: Core scoped app
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 08:17 AM
I ended up unable to use template.print in the document template script and used this successfully:
(function runTemplateScript(target /*GlideRecord for target task*/ ) {
//Add your code here to return the dynamic content for template
var cd = new GlideDate();
return (cd.getByFormat('MMMM dd, YYYY'));
})(target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 03:31 AM
Hi @ErinF ,
Can you check with the below code.
(function runTemplateScript(target /*GlideRecord for target task*/ ) {
var cd = new GlideDate();
cd.setDisplayValue(gs.nowDateTime());
template.print(cd.getByFormat("MMMM D, YYYY"));
})(target);
Just make sure that the scoped app has access to the "GlideDate" class and the "gs" global object, which are both provided by the ServiceNow platform. If these are not available in the scoped app, the script will not work.
Regards,
Shravan
Please mark it as helpful if this helps you.
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 06:04 AM
Hi Sai. Thank you for your comment. I appreciate it. I am getting the error that gs.nowDateTime cannot be used within my scoped app (Human Resources:Core). Any other ideas? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2023 02:14 AM
Hi @ErinF ,
Can you give it a try by using GlideDateTime.
-> This will give you the current date and time in the same manner as gs.nowDateTime().
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 08:17 AM
I ended up unable to use template.print in the document template script and used this successfully:
(function runTemplateScript(target /*GlideRecord for target task*/ ) {
//Add your code here to return the dynamic content for template
var cd = new GlideDate();
return (cd.getByFormat('MMMM dd, YYYY'));
})(target);