Date should not be day before today

Ashish Routray1
Tera Contributor

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; } } });

6 REPLIES 6

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

Harish KM
Kilo Patron
Kilo Patron

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;

}

Regards
Harish

Hi Harish But it is not reflecting in Agent workspace

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();

Regards
Harish