How to set current date in the Date field?

Anusha Savanth
Tera Expert

Start date is a Date Field. It should populate current date only when the B choice is selected on the A field.

Please help me.

1 ACCEPTED SOLUTION

Anusha Savanth
Tera Expert

Write a ONCHANGE client script 

var currentDate = new Date().toISOString().split('T')[0];
g_form.setValue('start_date',currentDate);

View solution in original post

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

@Anusha M 

this should work fine

javascript: var dt; var gdt = new GlideDateTime(); dt = gdt.getLocalDate(); dt;

OR

javascript: new GlideDateTime().getLocalDate();

Regards
Ankur

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

@Anusha M 

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

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

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi,

I just set the default to "now".

find_real_file.png

Execution result

find_real_file.png

Anusha Savanth
Tera Expert

Write a ONCHANGE client script 

var currentDate = new Date().toISOString().split('T')[0];
g_form.setValue('start_date',currentDate);

@Anusha M 

why to use client script when it can be done by server side without any script using default value?

Regards
Ankur

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