- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2017 09:48 AM
Hi guys!
I'm currently trying to get the last day of the month (current month), however, I can't seem to make the function "endOfThisMonth()" to work and I couldn't fin any examples on the internet. Does anyone know how to make this work?
I'll attach my code which runs from a business rule.
(function executeRule(current, previous /*null when async*/) { var queryDate = new GlideDateTime(); var dayOfMonth = 0; var expenseLine = new GlideRecord('fm_expense_line'); dayOfMonth = queryDate.getDayOfMonthUTC(); if (expenseLine.get('sys_id', current.u_expense_line)) { expenseLine.u_date_query_closed = queryDate.getDisplayValueInternal(); gs.log("If # 1 is true: ", "1C"); if (dayOfMonth <= 10) { queryDate.endOfThisMonth(); expenseLine.u_new_payment_due_date = queryDate; gs.log("If # 2 is true: "+ queryDate, "1C"); } else{ queryDate.addDaysLocalTime(30); expenseLine.u_new_payment_due_date = queryDate; } expenseLine.update(); } gs.log("Day of the Month: " + dayOfMonth, "1C"); gs.log("Date query closed: " + expenseLine.u_date_query_closed, "1C"); gs.log("New Payment Due Date: " + queryDate, "1C"); })(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2017 09:52 AM
Hi Samuel,
Check out setDayOfMonthUTC(). If you set it to something like 35, you'll get the last day of the month. Also, take a look at getDayOfMonthUTC().
The day of month to change to, from 1 to 31. If this value is greater than the maximum number of days in the month, the value is set to the last day of the month.
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_GDT-setDayOfMonthUTC_N
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2017 10:30 AM
this worked perfectly! thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2017 09:53 AM
The output will be in GMT with the format: yyyy-mm-dd huh:mm:ss
*** Script: 2017-09-01 06:59:59
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2018 02:08 AM
Please try this :
var gdt = new GlideDateTime();
gs.print(gdt.getDayOfMonth());