- 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 07:01 AM
tried same code but receiving error,
error:
Error occured while updating record: Operation against file 'resource_plan' was aborted by Business Rule 'Check Valid Dates^c56d90671b3f4250f98a2179b04bcb37'. Business Rule Stack:Check Valid Dates
- 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 08:03 AM
Thank you @Satishkumar B ..
worked..
- 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.
…………………………………………........................................................................................