Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Auto populate current date on date field

Lydon
Mega Expert

Hello 

I need help auto-populating the current date on a form using onChange. 

find_real_file.png

This is my current script and I just need the current date to display on the above form , I attempted 

var fecha = new Date();
	alert(fecha);

Not sure if that is the correct way . Thank you 

find_real_file.png

 

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

Try below code:

var today = new Date();
var todayStr = formatDate(today, g_user_date_format);
g_form.setValue("your_date_field", todayStr);
Best Regards
Aman Kumar

View solution in original post

7 REPLIES 7

Can you share the script instead of screenshot if possible.

@Jaspal Singh 

 

this is the script

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
if(g_form.getValue('state')=='100'){
g_form.setValue('u_reporting_agency',g_form.getValue('u_reporting_organization'));
    g_form.setValue('u_affected_environments',g_form.getValue('u_environment'));  
g_form.setValue('u_reported_by',g_form.getValue('caller'));
    if(g_form.getValue('date')!='u_date');
}

}

 
 
thank you 

Aman Kumar S
Kilo Patron

Try below code:

var today = new Date();
var todayStr = formatDate(today, g_user_date_format);
g_form.setValue("your_date_field", todayStr);
Best Regards
Aman Kumar