- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 02:31 AM
Hi,
I am having requirement, the end date field should automatically set to last date of month it was updated..
tried this script, not working..
Thanks in advance..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 05:36 AM
@lakshmi_laksh try the below code. i have tested the same:
var gd = new GlideDateTime();
gd.setValue('2024-08-08');
gd.addMonthsUTC(1);
gd.setDayOfMonthUTC(1);
gd.addDaysUTC(-1);
gs.info(gd);
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 06:43 AM
Why did you change this code?
gd = fd_data.trigger.current.end_date; // Get the current end date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 08:02 AM
@lakshmi_laksh Try this
var a = fd_data.trigger.current.end_date;
gs.log('end date FD'+a);
var gd = new GlideDateTime();
gd.setValue(a); // Get the current end date
// Calculate the last day of the month
gd.addMonthsUTC(1); // Move to the first day of the next month
gd.setDayOfMonthUTC(1); // Set day to the first of the next month
gd.addDaysUTC(-1); // Subtract one day to get the last day of the current month
return gd.getValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 05:11 AM
Hi @lakshmi_laksh Try below code
var currentDate = new GlideDateTime();
var glideDate = new GlideDate();
glideDate.setValue(currentDate.getDate().getDatePart());
glideDate.addMonths(1);
glideDate.setDayOfMonth(1);
glideDate.addDays(-1);
var endOfMonthDate = new GlideDateTime(glideDate.getValue());
gs.info("The last day of the month is: " + endOfMonthDate.getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 05:24 AM
Is this sample code helpful?
var gd = new GlideDateTime();
gd.setValue(fd_data.trigger.current.end_date); // Get the current end date
// Calculate the last day of the month
gd.addMonths(1); // Go to the first day of the next month
gd.addDaysUTC(-1); // Subtract one day to get the last day of the current month
// Set the calculated date as the new end date
fd_data.trigger.current.end_date = gd;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 06:18 AM
Hi @HIROSHI SATOH
I tried below , its throwing an error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 06:43 AM
Why did you change this code?
gd = fd_data.trigger.current.end_date; // Get the current end date