- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 03:35 AM
I need to get the name of previous month with year (no time required) .
My requirement is to display it on scheduled report subject.
Like for example : writing this on the subject javascript:"This report is for " + gs.now();
it displays the current date
. but i have to send the report for previous month.If the month is may 2017 .Then the subject should be like This report is for the month of April 2017.
How can i do this??
And if you can help me with how to write this thing in report header then it will be greatly helpful.
var monthNames = ',December,January,February,March,April,May,June,July,August,September,October,November'.split(',');
var gdt = new GlideDateTime();
var month=(monthNames[new GlideDate().getMonthLocalTime()]+":"+gdt.getYear());
It can be done by this code but how to put in the subject i am not getting any way
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 04:09 AM
Write a script include as below:
function month_year_call() {
var monthNames = ',December,January,February,March,April,May,June,July,August,September,October,November'.split(',');
var gdt = new GlideDateTime();
var month=(monthNames[new GlideDate().getMonthLocalTime()]+":"+gdt.getYear());
return month;
}
Subject line in report as: javascript:"This report is for " +month_year_call();
Mark Correct if this solves your issue and also hit Like and Helpful.
Regards,
Bubuprasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 06:31 AM
Below link might help you:
http://wiki.servicenow.com/index.php?title=PDF_Page_Header_Footer_Templates#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 07:59 AM
Hi All,
Please try this also:-
function test1(){
var gdt = new GlideDateTime();
gdt.addMonths(-1);
return (gdt.getDate().getByFormat("MMM-yyyy"));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 04:48 AM
var gr = new GlideDate();
gs.info(gr.getMonthUTC()) // returns current month
gs.info(gr.getMonthUTC()-1) // returns previous month
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 04:22 AM
Use this script,
var monthNames = [ "January", "February", "March", "April", "May", "June", |
"July", "August", "September", "October", "November", "December" ];
var date = new GlideDateTime(); | |
date = monthNames[date.getMonthLocalTime()-2]+":"+date.getYear(); |
If you want to call it as in email subject, create one mail script and call this notification body like this way,
var monthNames = [ "January", "February", "March", "April", "May", "June", |
"July", "August", "September", "October", "November", "December" ];
var date = new GlideDateTime(); | |
date = monthNames[date.getMonthLocalTime()-2]+":"+date.getYear(); | |
email.setSubject('This is the report of previous month '+date); |
call this in notification body: ${mail_script:<mail script name>}
Thanks,
Saikiran Guduri (NOW)
(Please mark the answer as correct answer/helpful/accept the sollution if it helps)