- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2018 01:44 PM
How to set Date Field to Current date using UI Action
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2018 01:49 PM
you need something like for date/time for date only use gs.now() instead of gs.nowDateTime()
UI Action
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name', 'nowDateTime');
ajax.getXML(function ()
{
g_form.setValue('put your field name here', ajax.getAnswer());
});
Script Includes
// Be sure the "Client callable" checkbox is checked
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor,
{
nowDateTime: function ()
{
return gs.nowDateTime(); }
});
As already pasted the link please use this method.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2018 01:49 PM
you need something like for date/time for date only use gs.now() instead of gs.nowDateTime()
UI Action
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name', 'nowDateTime');
ajax.getXML(function ()
{
g_form.setValue('put your field name here', ajax.getAnswer());
});
Script Includes
// Be sure the "Client callable" checkbox is checked
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor,
{
nowDateTime: function ()
{
return gs.nowDateTime(); }
});
As already pasted the link please use this method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2018 01:57 PM
It depends on the UI action type. For a server side type of UI action you can simply do:
var gdt = new GlideDateTime();
current.myDateFieldName = gdt.getDate();
You will need to replace myDateFieldName with the actual field you want to assign the date to 🙂
Thanks,
Berny