- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 09:35 AM
Hello
I need help auto-populating the current date on a form using onChange.
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 10:24 AM
Try below code:
var today = new Date();
var todayStr = formatDate(today, g_user_date_format);
g_form.setValue("your_date_field", todayStr);
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 09:48 AM
Hi Lydon,
Any specific reason to make it work onChange()? Is this having any dependancy on the field to populate date?
If not, you can simply pass default value to the Date field as
javascript: new GlideDateTime().getDate();
If so, i.e. it has dependancy then you need a combination of Script include & GlideAjax as in thread. It works on load but you can include it in your existing onChange() client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 09:54 AM
I just thought it will be easier to include it with my current onChange and the reason behind that is because when the form loads, those fields on the script auto-populates on the fields with previously entered data. But for the date, I will like for it to default to the current date.
I hope that explains my ask a bit more
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 09:57 AM
You can control it onLoad() as well by simply checking if Date field is empty or not.
Something as
if(g_form.getValue('date')!='')//repale date with field name here
{//set date code here
}
else{//ignore
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 10:06 AM