GlideDate Giving"Error while running Client Script "Valid Request Date": ReferenceError: GlideDateTi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 10:06 AM
I am trying to write a script that pulls a date variable and checks to see if it is 2 weeks from the current date, but I run into this error:
" Error while running Client Script "Valid Request Date": ReferenceError: GlideDateTime is not defined"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 11:43 AM
@edharris You are trying to use GlideDateTime which is a Server side object and not available via the client script. Instead you can choose to update your implementation as follows.
1. Create a Script include as follows.
Here is the source code.
var HRUtils = Class.create();
HRUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
compareDates: function() {
var request_date = this.getParameter('sysparm_request_date');
var requestDate = new GlideDateTime(request_date);
var currentDate = new GlideDateTime();
var daysDifference = GlideDate.subtract(requestDate, currentDate);
if (daysDifference < 14) {
return 'false';
}
return 'true';
},
type: 'HRUtils'
});
2. Here is how you should modify your client script.
function onSubmit() {
var ga = new GlideAjax('HRUtils'); // HRUtils is the script include class
ga.addParam('sysparm_name','compareDates'); // compareDates is the script include method
ga.addParam('sysparm_request_date',g_form.getValue('request_date')); // Set parameter sysparm_request_date
ga.getXML(getResponse);
// the callback function for returning the result from the server-side code
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer=='false'){
alert('A valid release date is required.');
return false;
}
return true;
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 12:56 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 07:08 PM
@edharris It looks like you are trying to use GlideDateTime in your client script, can you post the snapshot of your client script and script include here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 12:14 PM - edited 10-06-2023 12:15 PM
As already stated by a colleague , GlideDateTime is server side object, you need to calculate the difference on server side script i.e. script include.
To calculate difference of dates you can convert the complete date in milliseconds