How to add two years to a dates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 03:47 AM
Hi,
I need to update date field as tomorrow + 2years.
if I am submitting the form on 2 May 2022, it should display tomorrow + two years. after date is added field should be readonly
I am using below code in client script
gdt = new GlideDateTime().getDisplayValue();
gdt.addYears(2);
gdt.adddays(1);
gdt.getDate();
I am receiving errors in console
My scope is Human Resource
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 04:15 AM
Hi,
so you can use default value in the variable and it would show up when form loads
javascript: var date; var nowTime = new GlideDateTime(); nowTime.addDaysUTC(1); nowTime.addYearsUTC(2); date = nowTime.getDate(); date;
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 08:49 PM
@Surya
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 07:11 AM
Hi Surya,
Then you canuse the default value as suggested by Ankur.
If you want the value to be shown considering a schedule, then refer to this link.