onChange script error: ReferenceError: GlideDate is not defined function

Chenk
Tera Contributor

how to resolve the error: [onChange script error: ReferenceError: GlideDate is not defined function]

Chenk_0-1731317645764.png

 

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @Chenk,

 

GlideDate is a server side method and API, hence the error.

If you simply want the current date time now with no real other thought or consideration, you can use the following syntax to obtain the date via a Client Script.

However, best practice would be to leverage this type of data using something called 'AJAX' or "GlideAjax" (A method used when you need to leverage server side code)

I've attached a link to a great community post with examples of to how to achieve this and use AJAX code from your client script.

var date = new Date();

Link to community post: https://www.servicenow.com/community/developer-forum/client-script-date-time-functions/m-p/1457091

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie

View solution in original post

4 REPLIES 4

Juhi Poddar
Kilo Patron

Hello @Chenk 

 

GlideDate() is designed for server-side use only. If you need to perform date manipulation on the client side, you'll need to create a Script Include and then call it from the client script.

 

"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

Thank You
Juhi Poddar

 

 

dgarad
Giga Sage

Hi @Chenk 

 

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 answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Robbie
Kilo Patron
Kilo Patron

Hi @Chenk,

 

GlideDate is a server side method and API, hence the error.

If you simply want the current date time now with no real other thought or consideration, you can use the following syntax to obtain the date via a Client Script.

However, best practice would be to leverage this type of data using something called 'AJAX' or "GlideAjax" (A method used when you need to leverage server side code)

I've attached a link to a great community post with examples of to how to achieve this and use AJAX code from your client script.

var date = new Date();

Link to community post: https://www.servicenow.com/community/developer-forum/client-script-date-time-functions/m-p/1457091

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie

Simon Christens
Kilo Sage

Please use GlideAjax to make a server call and do the stuff in the script include.

There are ALOT of issues using Javascript Date()
An example:
https://medium.com/@raphael.moutard/handling-dates-in-javascript-the-wrong-way-d98cb2835200 

Its far more reliant to use a GlideAjax call and then do GlideDate / GlideDateTime in the server script.