Change Date field automcatilly to 1 Year from today
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited an hour ago
On kb_knowledge form when the workflow go to draft, I want to change the valid_to date to 1 year from today automatically.
I am able to do it but format is a issue correct formt is 10-Jan-2023 but while setting it is error out due to 2027-04-01 format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
you can use the below script logic
var gdt = new GlideDateTime();
var day = gdt.getDayOfMonthLocalTime();
var month = gdt.getMonthLocalTime();
var year = gdt.getYearLocalTime();
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
gs.print(day+'-'+ monthNames[month]+'-'+year);
Thanks ands Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @Ashish Kathait — just want to flag that the format string above (01-Apr-2027) is actually the UI display format, not the value format ServiceNow expects. Setting a glide_date field using that string will likely cause the same error or set the field incorrectly.
The good news: yyyy-MM-dd is the correct internal format for glide_date fields, so you're actually close. The issue is probably in how you're setting the value, not the format itself.
Here's a Business Rule approach that should work:
var gdt = new GlideDateTime();
gdt.addYears(1);
current.valid_to.setValue(gdt.getDate().getValue()); // returns yyyy-MM-dd
If you're using Flow Designer instead, use the "Add Duration" action to add 1 year to today's date, then set valid_to from that output — it handles the format automatically.
If you're still seeing an error, share the script you're using and where it's throwing — happy to help debug.
