- 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 04:07 AM
Hi Suprakash,
You can use service now date function like beginningOfLastMonth() to achieve this requirement. The function returns the date and time of beginning of the previous month. The output of the function will be in the format of yyyy-mm-dd hh:mm:ss. Since you need no time you can convert the date into string and analyse the result.
Please mark helpful/Correct if you find this useful.
Regards,
Siddartha Gudimalla.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2020 07:55 AM
- 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 05:01 AM
Thanks Bubuprasad ,
Its working greatly .Just one more favor is there any way that we can implement the same in the Pdf page header footer template ???????
so that we donot need to use it in the subject . it will display it in the pdf itself