How to retrieve Milliseconds from a Glide Date Time field in a client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2010 08:29 AM
Hello,
In the table incident, I have a field named "u_my_date" of glide_date_time type. But from the client script, each time I use g_form.getValue('u_my_date') it just return a string (i guess).
Could someone please tell me how I could retrieve the time in milliseconds from the u_my_date field?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2010 01:58 PM
When working with date time values in client scripts you will need to create a global business rule to perform any date calculations, comparisons, or conversions. Then call the BR from the client script using AJAXEvaluateSynchronously and have the BR return the data back to your client script.
Example on change Client script calling a global business rule:
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading) {
if(newValue != '') {
if (newValue != oldValue) {
var script = "clientDataEnd('" + newValue + "')";
var answer = AJAXEvaluateSynchronously(script);
if(answer == 'true'){
alert('The maximum amount of time you can request temporary access for is 30 days from now.');
g_form.setValue('access_end', oldValue);
}
}
}
}
}
Example of the global BR it the client script calls:
function clientDataEnd(end){
var anActualDate = new Packages.com.glide.glideobject.GlideDateTime();
anActualDate.setDisplayValue(end);
var dt = gs.daysAgo(-30);
var answer = 'false';
if (anActualDate > dt) {
answer = 'true';
}
return answer;
}
You can use the above example as a guide to create the business rule and client script portions then look at the below wiki article to figure out how to return the milliseconds if that's what you want returned.
http://wiki.service-now.com/index.php?title=Embedded:GS_Date_Time_Doc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2010 06:01 AM
Thank you for your instruction. It works.
Best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2015 03:35 AM
Hi
Check these links, these might help you
getNumericValue() - GlideDateTime - ServiceNow Wiki
setNumericValue(milliseconds) - GlideDateTime - ServiceNow Wiki