Set a date via a flow based on dynamic year

Bidduam
Tera Guru

I am trying to set a flow variable that I've called - next_audit_date

 

What I want to do is to set the value of the flow variable to be june 30 of the year that that date comes next on.

 

EG: if it is 20 may, then set date as June 30, current year (2025)

If it is 10 July, then set the date to be June 30 the next year (2026)

 

Anyone able to help please?

2 ACCEPTED SOLUTIONS

James Chun
Kilo Patron

Hi @Bidduam,

 

This may need bit of testing but try the following code to set your flow variable:

var nowGD =new GlideDate();
var year = nowGD.getYearNoTZ();
if( !((nowGD.getDayOfMonthNoTZ()) < 30 && (nowGD.getMonthNoTZ() <= 6)))
{
	year ++;
}

var auditGD = new GlideDate();
auditGD.setDisplayValue(year + '-06-15');

return auditGD;

View solution in original post

J Siva
Kilo Patron
Kilo Patron

Hi @Bidduam 
Try the below script.

var today = new GlideDateTime();
var currentYear = today.getYear();
var june30th = new GlideDateTime();
june30th.setValue(currentYear+'-06-30'); // set to a known date for comparison
gs.print(june30th);
if (today.before(june30th)) {
    var june30thThisYear = new GlideDateTime();
    june30thThisYear.setValue(currentYear + '-06-30');
    // set the custom variable value
   return june30thThisYear;
} else {
    var june30thNextYear = new GlideDateTime();
    june30thNextYear.setValue((currentYear + 1) + '-06-30');
    // set the custom variable value
    return june30thNextYear;
}

JSiva_0-1748238868913.png

Output:

JSiva_1-1748238889384.png

Regards,
Siva

View solution in original post

7 REPLIES 7

rebecca65bell
Mega Contributor

@Bidduam wrote:

I am trying to set a flow variable that I've called - next_audit_date

 

What I want to do is to set the value of the flow variable to be june 30 of the year that that date comes next on.

 

EG: if it is 20 may, then set date as June 30, current year (2025)

If it is 10 July, then set the date to be June 30 the next year (2026)

 

Anyone able to help please?


To set your next_audit_date flow variable to June 30 of the relevant year, compare the current date to June 30 of the current year. If today's date is on or before June 30, the next_audit_date will be June 30 of the current year. If today's date is after June 30, then the next_audit_date will be June 30 of the next year. This logic ensures you always pick the upcoming June 30.

James Chun
Kilo Patron

Hi @Bidduam,

 

This may need bit of testing but try the following code to set your flow variable:

var nowGD =new GlideDate();
var year = nowGD.getYearNoTZ();
if( !((nowGD.getDayOfMonthNoTZ()) < 30 && (nowGD.getMonthNoTZ() <= 6)))
{
	year ++;
}

var auditGD = new GlideDate();
auditGD.setDisplayValue(year + '-06-15');

return auditGD;

@James Chun 

That appears to work perfectly thank you 🙂

Of course I can't test if it works after 30 June currently, but certainly works for now. Thanks again

J Siva
Kilo Patron
Kilo Patron

Hi @Bidduam 
Try the below script.

var today = new GlideDateTime();
var currentYear = today.getYear();
var june30th = new GlideDateTime();
june30th.setValue(currentYear+'-06-30'); // set to a known date for comparison
gs.print(june30th);
if (today.before(june30th)) {
    var june30thThisYear = new GlideDateTime();
    june30thThisYear.setValue(currentYear + '-06-30');
    // set the custom variable value
   return june30thThisYear;
} else {
    var june30thNextYear = new GlideDateTime();
    june30thNextYear.setValue((currentYear + 1) + '-06-30');
    // set the custom variable value
    return june30thNextYear;
}

JSiva_0-1748238868913.png

Output:

JSiva_1-1748238889384.png

Regards,
Siva