Set default date on date field

PrandeepSharma
Tera Contributor

Hi,

I just created a new Date field that shows only when incident on hold. I am trying to set a default date using dictionaries default value, however none of the javascript GlideDateTime seem to work.

I just need to set the default value to be 6 days from current date. Please help

11 REPLIES 11

AishwaryaShukla
Kilo Guru
Kilo Guru

Hi @PrandeepSharma 

 

You can use a 'before' business rule to set the default value of the date. The BR should run when the state changes to on hold, then you can use the GlideDateTime() api to set the desired date. (in this case it would be 6 days after the current date time).

Regards,
Aishwarya

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello @PrandeepSharma ,

 

Put this in the default value of the field dictionary

 

javascript:   var gdt = new GlideDateTime();gdt.addDays(6);gdt.getDate();

 

Note (instead of &colon use colon symbol)

BR,
Nayan

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Hi I added javascript: var gdt = new GlideDateTime(); gdt.addDays(6);gdt.getDate(); and after the field appears on the form is still blank

Community Alums
Not applicable

Hi @PrandeepSharma 

This should work for you: javascript: var gdt = new GlideDateTime(); gdt.addDays(6);gdt.getDate();

Hope it helps.

Please mark my response as helpful or correct based on the impact