- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 09:50 PM
Hi ALL,
I have a variable with Date Type and I want the variable to auto populate current date. I used onChange client script with below script but no date populated. Could you please help with a script to achieve this requirement. Thank you.
var dFormat = g_user_date_format;
var tdayDate = formatDate(new Date(),dFormat);
g_form.setValue('todayDate', tdayDate);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 09:55 PM
Hey Rich,
Go to variable dictionary (right click on the variable) and in default value write this: javascript:gs.nowDateTime()
If it works the please mark my answer Correct and Helpful.
Thanks and Regards:
Utpal Dutta

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 11:05 PM
Hey Rich,
I'm glad that my solution worked for you. Try this client script for the requester title.
var caller = g_form.getReference('caller_id', doAlert);
function doAlert(caller) {
g_form.setValue(your field name, caller.title);
}
Please mark my answer Correct and Helpful.
Thanks and Regards:
Utpal Dutta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 11:15 PM
No luck so far. I am guessing i need to change maybe 'caller" to the variable name?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 05:53 AM
Hi Rich,
just to inform as you have mentioned the variable type is Date so this won't work as it would return date/time
javascript:gs.nowDateTime()
Also the function nowDateTime is not allowed in scope; so please refer below
For Date/Time Variable Default
javascript: new GlideDateTime();
For Date Variable Default to today
javascript: new GlideDateTime().getDate()
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 04:33 PM
Correct

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 10:05 PM
Hi there,
For a variable, you can just add a default value. Looking at your description, I don't see a reason for using a (Catalog) Client Script.
Some examples:
javascript:new GlideDate();
javascript:new GlideDateTime();
javascript:gs.nowDateTime();
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field