- 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 09:52 AM
Hi Samuel, try using gs
gs.endOfThisMonth();
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2017 10:06 AM
the function worked, but my log is giving me 2017-09-01 instead of 2017-08-31 (the end of this month)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2017 09:52 AM
https://community.servicenow.com/thread/225958
Thanks.
PS: Hit like, Helpful, Correct and Endorse, if it answers your question.

- 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