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 05:51 AM
Hey @Surya
Please Use below in variable default value:
javascript:gs.daysAgo(-366);//one year and a day
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 03:57 AM
Hi,
you can add day to current date and then add years
why to use client script when it can be done with business rule?
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 04:01 AM
In catalog item that variable is there
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 04:02 AM
Hi,
when should that variable be populated?
what's the trigger point?
If it's not required during submission then you can use workflow run script to do this
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 04:10 AM
When ever we open catalog item, variable is available on form