Glide Date Time -Catalog client script

Gousia Syed1
Tera Contributor

 

 

Is it valid to use GlideDateTime object and GlideDate for date field in catalog client script. I mean on client side?

 

Thanks,

Ruby

4 REPLIES 4

Sagar Pagar
Tera Patron

Hi @Gousia Syed1,

 

The GlideDateTime object and GlideDate are APIs used in Server side scripts. To use in client side scripts you have to use it Script include s and get it using GlideAjax call.


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi Sagar,

 

Thank you for the response. Can we use Date object like below in "onchange" client script.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var sd = new Date(g_form.getValue('start_date'));
var ed = new Date(g_form.getValue('end_date'));

 

If not, can you please explain in detail, it would be help ful.

 

Thanks,

Ruby

Hi @Gousia Syed1,

 

Yes. you can easily get the current date time by using new Date() object in client scripts.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var sd = new Date(g_form.getValue('start_date'));
var ed = new Date(g_form.getValue('end_date'));

alert("sd: " + sd + " ed: " + ed);
}

 

Output:

sd: Thu Jun 10 2021 23:40:10 GMT+0530 (India Standard Time) ed: Sun Oct 10 2021 23:42:16 GMT+0530 (India Standard Time)

 

For reference take a look at this article: Client Side Dates in ServiceNow 

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi @Gousia Syed1,

 

Have you look into it? Let me know if you stuck and need any help.

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow