How to Get the current date time using a client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 09:33 AM
Hello
How to Get the current date time using a client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2022 07:34 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
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
‎05-13-2025 04:05 AM
This was very helpful and solved our problem passing current date & time to a UI action triggered subflow
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2022 10:10 AM
Hi
It is not best practice to use server side calls using client script, so I have done it through glide ajax.
Use the below code, Tested and Working fine.
Client Script
function onLoad() {
var ga = new GlideAjax('MyDateTimeAjax');
ga.addParam('sysparm_name', 'nowDateTime');
ga.getXML(SettingDate);
function SettingDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('give_fieldname_here', answer);
}
}
Script Include
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
nowDateTime: function() {
return gs.nowDateTime();
}
});
I hope it helps, if so please mark it as both helpful and correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 09:53 PM
if you want only date then just replace the below line in the script include in the above code.
return gs.now();
I hope it helps, if so please mark it as both helpful and correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2022 07:32 PM
