Need help on setting default value with on the date variable

shaik_irfan
Tera Guru

Hi,

 

I am scopped application we have a variable called Due date where i need to auto populate of next month

 

Example: 

Today date: 8/3/2020

I need to set the default value as: 9/3/2020

In the default value when i use  new GlideDateTime().getDisplayValue(); i am able to get the current data but i unable to add 1 month. 

 

Can anyone please help me how to do this

 

1 ACCEPTED SOLUTION

Chander Bhusha1
Tera Guru

Hi shaik,

You can use this in the default value: to add one month to the current date

javascript:   var gdt = new GlideDateTime();gdt.addMonths(1);gdt.getDisplayValue();

You can also use addMonthsLocalTime() function to add months in local date.

 

 

Thanks,

CB

View solution in original post

4 REPLIES 4

Chander Bhusha1
Tera Guru

Hi shaik,

You can use this in the default value: to add one month to the current date

javascript:   var gdt = new GlideDateTime();gdt.addMonths(1);gdt.getDisplayValue();

You can also use addMonthsLocalTime() function to add months in local date.

 

 

Thanks,

CB

with this condition can I exclude weekends(sat, sun)

Could you please share the condition for excluding weekends for the above code.

Subhojit Das
Kilo Guru

Hi Irfan,

Try to add the code in default value in the dictionary of the field you are using.

1) If Field type= Date

javascript:var glideGD=new GlideDateTime();glideGD.addDays(30);glideGD.getDate();

2) If Field type= Date/Time

javascript:var glideGDT=new GlideDateTime();glideGDT.addMonths(1);glideGDT.getDisplayValue();

https://developer.servicenow.com/dev.do#!/reference/api/madrid/server_legacy/c_GlideDateTimeAPI#r_GD...

Please mark as Correct and Helpful if your issue was resolved with the solution provided.

Regards,

Subhojit Das