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 03:03 AM
add below line in script include code.
var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//Returns the Date/Time of right now.
getNowDateTime: function(){
var gdt = new GlideDateTime(current.start_date);
var hours = 60*60*12;
gdt.addSeconds(hours);
return gdt.getDisplayValue();
},
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2020 05:38 AM
Hi,
Refer this Code it will also help you.
I have created one UI action on problem table and after triggering UI action it will set current date as a u_start_date and aslo add 1 hour in current date and set it to u_end_date field in incident.
var gdt = new GlideDateTime(gs.nowDateTime());
var gtime1 = new GlideTime();
gtime1.setValue("01:00:00");
gdt.add(gtime1);
var gtime2 = gdt.getTime();
gs.addInfoMessage((gtime2.getByFormat('hh:mm:ss'))); //it will add 1 hour in current date
var gr = new GlideRecord("incident");
gr.addQuery('problem_id',current.sys_id); //your query to update perticular incident
gr.addQuery('u_meeting_room','false'); //this field is true it will not update
gr.query();
if(gr.next())
{
gr.start_time = gs.nowDateTime();
gr.end_time = gtime2.getByFormat('hh:mm:ss');
gr.u_meeting_room = 'true'; // Make it true u_meeting_room checkbox
}
//gr.update();
var sys_ID=gr.update(); //pass the sys_id to the query below in setRedirectURL method
//gs.addInfoMessage("sysID="+sys_ID);
action.setRedirectURL('incident.do?sys_id='+sys_ID+'&sysparm_record_target=incidentactive%3Dtrue%5EEQ&active=true&sysparm_clear_stack=true&sysparm_record_row=1&sysparm_record_rows=44&sysparm_record_list=active%3Dtrue%5EORDERBYDESCsys_created_on'); //here you can pass your target table url with sys_id of current record
I hope it will help you.
Please mark Correct/Helpful answer if it help you in any way.
Thanks and Regards,
Kunal.