- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2022 04:26 PM
Hi Community,
We are creating a record producer on our Service Portal for hardware return in the office. The form is pretty straightforward and has been easy to make. One of the questions is the date of hardware return. Currently, it requires the user to click into the menu and choose the date. Is there any way to make it so that the date field auto-fills to the current date?
It is a small thing but I want to keep the number of user actions on this form to a minimum!
Thank you!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2022 07:08 PM
Hey,
Just use this in default value of the variable javascript: new GlideDate();
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2022 05:37 PM
Hello name,
You can set a default value for the variable.
Use gs.getDateTimeNow(); if it's Date/Time
Use gs.getDateNow(); if it's Date
Please mark my answer as correct/helpful if it has helped you.
Thanks,
Logan
--
LinkedIn

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2022 07:01 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2022 07:07 PM
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2022 07:34 PM
My bad.
now is just a shorthand for gs.now(). This, however, would return date in UTC.
To get the date in user's timezone, use the following:
javascript: (new GlideDate()).getDisplayValue()
Timezone problem becomes apparent if the type is set to Date/Time.
Setting the default to "javascript: new GlideDateTime()" would result in the wrong time because ServiceNow's internal timezone is UTC.
Execution result:
case 1: using just "new GlideDateTime()". The time is in UTC.
case 2: using "(new GlideDateTime()).getDisplayValue(). Time is in end-user's timezone.
Likewise, it's is necessary to use (new GlideDate()).getDisplayValue() to get the correct date in end-user's timezone.