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 05:56 AM
The issue is that you don't have access to gs in client scripts so you will have to use a AJAX call. See the link below.
http://wiki.service-now.com/index.php?title=Set_Current_DateTime_In_Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2011 09:39 AM
I get a NULL value when I use the ajax call example in the wiki.
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2011 11:42 AM
You could also try to create a global business rule and call it something like getDtCurrent. Create a function in the BR that returns the current date time.
function getDtCurrent(){
var dtcurrent = gs.nowDateTime();
return dtcurrent;
}
Then call this BR from the client script with an Ajax call like this.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue != oldValue) {
return;
}
else{
var script = "getDtCurrent()";
var answer = AJAXEvaluateSynchronously(script);
g_form.setValue('u_flag_date', answer);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2011 07:20 PM
Thank you Jay but it is still giving me a "null" value.
Would it be easier if I changed the 'u_flag_date' type from glide_date_time to datetime?