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

Sid_Takali
Kilo Patron
Kilo Patron

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

HIROSHI SATOH
Mega Sage

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;

 

Hi @HIROSHI SATOH 
I tried below , its throwing an error

var gd = new GlideDateTime();
gd = fd_data.trigger.current.end_date; // Get the current end date
gd.addMonths(1);
gd.addDaysUTC(-1);
fd_data.trigger.current.end_date = gd;
return gd;



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