The CreatorCon Call for Content is officially open! Get started here.

How to retrieve Milliseconds from a Glide Date Time field in a client script?

Not applicable

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.

3 REPLIES 3

Jay_Ford
Kilo Guru

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


Not applicable

Thank you for your instruction. It works.

Best regards,


Anurag Tripathi
Mega Patron
Mega Patron

Hi



Check these links, these might help you


getNumericValue() -   GlideDateTime - ServiceNow Wiki


setNumericValue(milliseconds)   - GlideDateTime - ServiceNow Wiki


-Anurag