How to populate the current date/time on a field using client callable UI Action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2020 02:05 AM
Hi All,
I am trying to populate the current date/time on field using client callable UI Action.
I am having a UI action 'Create Meeting'. When user click on the button, the meeting form will open and it should have the current date/time as 'u_start_date' & add 1hr from current time as 'u_end_date'. Below is the code I am trying.
function openFormDialog() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
var tt = new Date().getTime();
alert(tt);
if(dd<10){
dd='0'+dd;
}
if(mm<10){
mm='0'+mm;
}
var toy = dd+'/'+mm+'/'+yyyy;
alert(toy);
var gModalForm = new GlideModalForm('Create Meeting', 'u_meetings');
gModalForm.setPreference('sysparm_view', 'new');
gModalForm.addParm('sysparm_query', 'u_customer_account = ' + g_form.getUniqueValue() + '^u_start_time =' + toy);
gModalForm.setCompletionCallback(function(action_verb, sys_id, table, displayValue) {
});
gModalForm.render();
}
- Thank you.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2020 02:09 AM
try with glide ajax.
sample code.
Client script:
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDateTime');
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
Script Include:
var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//Returns the Date/Time of right now.
getNowDateTime: function(){
var now = gs.nowDateTime(); //Now Date/Time
return now;
},
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2020 02:11 AM
Hi Harsha,
But I want the date/time to be populated through client callable UI action only. Can you please help?
- Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2020 02:14 AM
you just have to use glide ajax inside your client callable ui action , that will work.
Blog for further reference.
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2020 02:38 AM
Harsha,
can you help me on how to add 1hour for current date/time and populate on 'u_end_date' field?
- Thank you.