- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2025 10:04 PM - edited 05-25-2025 10:05 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2025 10:41 PM
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2025 10:54 PM
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;
}Output:
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2025 11:00 PM
Thank you, I had already just gotten a solution from @James Chun , however I have also tested yours and it also looks to work as I'd want it to, so I will also mark yours as a solution since ServiceNow now allows for more than one reply to be a solution.
Thank you very much for your reply and answer, I really appreciate always getting so much help in this forum 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2025 11:14 PM
@Bidduam Glad it helped 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2025 10:54 PM
Hi
@Bidduam
(function execute(inputs, outputs) {
var today = new GlideDateTime();
var currentYear = parseInt(today.getYearLocalTime());
// Create a GlideDateTime for June 30 of current year
var june30 = new GlideDateTime(currentYear + "-06-30 00:00:00");
// If today is after June 30, set it for next year
if (today.after(june30)) {
currentYear += 1;
june30 = new GlideDateTime(currentYear + "-06-30 00:00:00");
}
// Set the flow output variable
outputs.next_audit_date = june30;
})(inputs, outputs);
If my response helped please mark it correct
Thanks, and Regards,
Suyash
