- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 01:34 AM
how to resolve the error: [onChange script error: ReferenceError: GlideDate is not defined function]
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 01:47 AM - edited 11-11-2024 02:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 01:39 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 01:44 AM
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.
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 01:47 AM - edited 11-11-2024 02:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 02:03 AM
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.