Client script OnChange and javascript:gs.nowDateTime()

perl95110
Kilo Explorer

I have created 2 fields ( u_flag, u_flag_date) in the incident form
u_flag is type "True/False"
and
u_flag_date is of type "glide_date_time".
I am try set the 'u_flag_date' with the current date-time if 'u_flag' is checked.
My client script below is not working. Can anyone tell me what I am doing wrong?


function onChange(control, oldValue, newValue)
{
if (oldValue == newValue)
{
return;
}
else
{
//var endDateTime = gs.nowDateTime();
var endDateTime = new GlideDateTime(gs.nowDateTime());
g_form.setValue('u_flag_date',endDateTime);
}
}

11 REPLIES 11

Jay_Ford
Kilo Guru

Taking imartez's suggestion into account if you change your script to this it should clear the field when the checkbox is unchecked.



function onChange(control, oldValue, newValue){

var ctime = g_form.getValue('u_flag');

if (ctime == 'true'){
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name','nowDateTime');
ajax.getXML(setDateTimeParse);

}
else{
alert ("Clear date field");
g_form.setValue('u_flag_date','');
}


}

function setDateTimeParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_flag_date', answer);

}


Thanks Jay and Imartez