Set current date time using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 09:38 PM - edited 06-03-2024 09:42 PM
Hi,
We have a scenario when state changes to Assigned, the assigned date field should get update with current date time.
I am trying to on change client script with below script but it has update with incorrect format.
Please suggest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 09:49 PM
Hello Divya,
Could you try this :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 09:53 PM
Hello @DivyaNarayG ,
Try using below
var today_date = new Date();
var today_date_str = formatDate(today_date, g_user_date_format);
var strtDate = today_date_str;
Thanks,
Valmik Patil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 09:53 PM
try this if the field is date/time
if (newValue == '1') {
var today_date = new Date();
var today_date_time_str = formatDate(today_date, g_user_date_time_format);
g_form.setValue('assigned_date', today_date_time_str);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 01:01 AM
Hi Ankur,
Thanku. But this sets the value in local timezone. How can we update the value with system timezone.