Date should not be day before today
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 01:35 AM
I have one field called "Extended Date" that date should not be day before today.
So the issue is when i am using any client script and script include for this it reflect in both Native UI and Agent Workspace in My PDI but When I Implement this code in my client instance its is not working.beacuse that case table i am created in customer service scope.
client script:
field_name:u_extended_date
function onChange(control, oldValue, newValue, isLoading)
{
if(isLoading){ return; }
if(newValue != ''){
var ga = new GlideAjax('CheckDate');
ga.addParam('sysparm_name', 'chkCatDate');
ga.addParam('sysparm_date',g_form.getValue('u_extended_date'));
ga.getXML(DatParse);
}
function DatParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'false'){
g_form.addErrorMessage("Date cannot exist in past.");
g_form.setValue('u_extended_date', ''); // Empty the variable.
}}}
Script Include:
var CheckDate = Class.create();
CheckDate.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
chkCatDate : function(){
var start = this.getParameter('sysparm_date');
var currDay = gs.now();
if(start < currDay){
return false;
}
else
{ return true; } } });
- Labels:
-
Agent Workspace

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 01:47 AM
Hi there,
Try to add some debugging. To see up to which point your script is working, from where it is failing, what the outcome of variables is, etc..
For example, is the Client Script triggered at all? Is the Script Include reached? What is the contents of the answer, and is it what you would expect? Etc..
Adding simple debugging like this, will save you hours.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 02:20 AM
Hi You could use onchange client script for date variable
var date = g_form.getValue('date'); //date is the variablename
date = new Date(Date.parse(date.replace(/-/g,' ')));
var today = new Date();
today.setHours(0,0,0,0);
if (date < today) {
alert('The date cant be in the past. Please pick another date.');
return false;
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 04:07 AM
Hi Harish But it is not reflecting in Agent workspace

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 07:34 PM
HI var currDay = gs.now(); in your script include
gs.now() will not work in scoped applications.
The best way to use in scoped applications is using new GlideDateTime();
Harish