- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2017 12:06 PM
Hi All,
I found below details from one of the thread to restrict past date selection in catalog item however the same is not working in Normal table form, please suggest how to achieve the same in normal table forms (reference- https://community.servicenow.com/thread/159148😞
____________________________________________________________________________
OnChange Client Script : field name : date_time
Script :
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('date_time'));
ga.getXML(DatParse);
}
function DatParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'false'){
alert("Date cannot exist in past.");
g_form.setValue('date_time', ''); // Empty the variable.
}}}
___________________________________________________________________________
Now write a script include as follows :-
Name : CheckDate
Client callable : true
Script :
var CheckDate = Class.create();
CheckDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
chkCatDate : function() {
var start = this.getParameter('sysparm_date');
var currDay = gs.now();
if(start < currDay){
return false;
}
else
{ return true; } } });
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2017 12:36 PM
Hello
Try this and let me know if i can help you with anything.
Script Include:
Name:DateValidation
Client callable: Checked
var DateValidation = Class.create();
DateValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateDate: function() {
var ActualEndDate = this.getParameter('sysparm_end_date');
return gs.dateDiff(gs.now(),ActualEndDate, true)/86400;
},
type: 'DateValidation'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('DateValidation');
ga.addParam('sysparm_name','validateDate');
ga.addParam('sysparm_end_date',g_form.getValue('u_business_need_by_date'));//give your date field
ga.getXML(ProcessResult);
function ProcessResult(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer < 0)
{
g_form.clearValue('u_business_need_by_date'); //give your date field
alert('Business need date should not be in the Past.');
}
}
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2020 02:26 PM
Now I understand. Thanks for clarifying.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2023 04:01 AM
Hi ,
I am getting below message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2021 09:11 AM
Hi, I am facing the same issue and have come across this post. I have tried the above script for my scoped app however it does not work, I am fairly new to dev...is anyone able to help please.
Below is my client script and script include:
Thank you