Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to set current Date and time

Jishnu C Gopal
Kilo Contributor

How to set Date Field to Current date using UI Action

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

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.

View solution in original post

2 REPLIES 2

Mike Patel
Tera Sage

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.

bernyalvarado
Mega Sage

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