How to add two years to a dates

Surya67
Tera Contributor

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

12 REPLIES 12

Hey @Surya

Please Use below in variable default value:

javascript:gs.daysAgo(-366);//one year and a day
Best Regards
Aman Kumar

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

In catalog item that variable is there

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

When ever we open catalog item, variable is available on form