Client script OnChange and javascript:gs.nowDateTime()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2011 01:00 AM
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);
}
}
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2011 07:48 PM
I've got it now. I was missing the script include part
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2011 03:17 PM
I am changing my client script a little bit. When the flag is checked (true) , put the date-time and when the flag is uncheck , clear the date field.
My script is not doing what I want. Anyone can give me a clue?
function onChange(control, oldValue, newValue)
{
if (oldValue == newValue)
{
return;
}
else
{
var ctime = g_form.getValue('u_flag');
alert(newValue);
if ( ctime == true)
{
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name','nowDateTime');
ajax.getXMLWait();
var rightnow = ajax.getAnswer();
g_form.setValue('u_flag_date', rightnow);
}
else
{
alert ("Clear date field");
g_form.setValue('u_flag_date','');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2011 07:11 AM
Try the following, too (it would save an AJAX call if it works):
var endDateTime = new GwtDate().now().serializeInUserFormat(false);
g_form.setValue('u_flag_date', endDateTime);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2011 09:36 AM
I still get an error
'GwtDate' is undefined

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2011 06:17 AM
I don't like using the getXMLWait method because it locks the browser until an answer is returned. I just tried this in my instance. I created 2 fields, the first field was a Yes/No variable, the second field was a date/time field. Here is the code.
Script Include -
Name: MyDateTimeAjax
Client Callable: true
Script:
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
nowDateTime: function() {
return gs.nowDateTime();
}
});
Client Script -
Name: set the date
Type: onChange
Applies to: Catalog Item
Script:
function onChange(control, oldValue, newValue, isLoading) {
if(newValue == "Yes"){
var ga = new GlideAjax('MyDateTimeAjax');
ga.addParam('sysparm_name', 'nowDateTime');
ga.getXML(setDateTimeParse);
}
function setDateTimeParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('my_date_field', answer);
}
}