- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2022 01:05 PM
I have a requirement for a variable to display month and year. However, there is no OOB method for this. I have two options, and i want to know how feasible this is and how do i do it. the options are;
- Block out all dates except the last day of the month in calender or
- Throw an error message if any other day but the last day of the month is selected.
Any help is appreciated.
Thanks
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 12:24 PM
Thanks for your response. When i try your code, it sets the date as below.
What could be the issue here?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2022 01:13 PM
Hi,
I would add another 2 options
a. Keep standard date format as soon as the person selects certain day, set the date to the last day of that month and show info message (more user friendly than error message and forcing user to do another selection)
b. Simply have a variable of the date but do not show it in the form and in the form rather have two select boxes with list of months and list of years. Upon submit calculate the date for the date variable and show that one in the RITM/SCTASK form.
I would personally go for b.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2022 01:38 PM
Hi Remy,
I would create an onChange() script on the date field to change the date to the last day of the month.
That is, I'll let end-user pick the day, but will let ServiceNow change the date to the last day of the month.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2022 02:29 PM
Something like below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var curDate = getDateFromFormat(newValue, g_user_date_format);
curDate = new Date(curDate);
var lastDay = new Date(curDate.getFullYear(), curDate.getMonth() + 1, 0);
lastDay = lastDay.getFullYear() + '-' + zeroPad((lastDay.getMonth()+1)) + '-' + zeroPad(lastDay.getDate());
if (newValue != lastDay) {
g_form.setValue('last_day_of_month', lastDay);
}
function zeroPad(d) {
return ('00'+d).slice(-2);
}
}
Execution results:
Step 1: Enter date
Step 2: Changed to last day of month
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 12:24 PM