How to update 'End date' field to automatically to set to current month end date in flow designer

lakshmi_laksh
Tera Contributor

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..

var currentDate = new GlideDateTime(fd_data.trigger.current.end_date);
var time = currentDate.getDayOfMonthUTC();
return time;
3 ACCEPTED SOLUTIONS

Satishkumar B
Giga Sage
Giga Sage

@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);

 

 

SatishkumarB_0-1723206846626.png

 

…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution !! If this helps you to understand.

…………………………………………........................................................................................

 

View solution in original post

Why did you change this code?
gd = fd_data.trigger.current.end_date; 
// Get the current end date

View solution in original post

@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();

View solution in original post

8 REPLIES 8

Hi Hiroshi,
tried same code but receiving error,

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;
return gd;


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
 

@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();

Thank you @Satishkumar B ..
worked..

Satishkumar B
Giga Sage
Giga Sage

@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);

 

 

SatishkumarB_0-1723206846626.png

 

…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution !! If this helps you to understand.

…………………………………………........................................................................................