- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2022 08:57 AM
Hi
I have a requirement, in catalog form there is date/time field while entering the date, next 7 days user should not able to enter it for example today is NOV 23 and user is raising the request today means user should not able to select nov 23 24 25 26 27 28 29 from nov 30 only he can able to select in the field. Similarly, if today is nov 24 then 24 25 26 27 28 29 30 shouldnot be selectable
Please help me with the full script
Thanks & Regards,
Suuriya
Solved! Go to Solution.
- Labels:
-
ITSM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2022 09:32 AM
Hi @suuriya ,
Use catalog client script : Type Onchange , Select proper catalog and variable name
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga=new GlideAjax("getCallerDetails");
ga.addParam('sysparm_name',"getDetails");
ga.addParam('sysparm_date',newValue);
ga.getXMLAnswer(getResult);
function getResult(response){
if(response =='false'){
alert("Please select date after 7 days from now");
g_form.clearValue('date');
}
}
}
Script Include:-
var getCallerDetails = Class.create();
getCallerDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var currentDate = this.getParameter('sysparm_date');
var gdt = new GlideDateTime();
gdt.addDays(6);
if(currentDate>gdt.getDisplayValue()){
return true;
}else{
return false;
}
},
type: 'getCallerDetails'
});
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2022 09:10 AM
Hello,
You can use an UI policy to do this.
Please check the below article for the same:-
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2022 09:32 AM
Hi @suuriya ,
Use catalog client script : Type Onchange , Select proper catalog and variable name
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga=new GlideAjax("getCallerDetails");
ga.addParam('sysparm_name',"getDetails");
ga.addParam('sysparm_date',newValue);
ga.getXMLAnswer(getResult);
function getResult(response){
if(response =='false'){
alert("Please select date after 7 days from now");
g_form.clearValue('date');
}
}
}
Script Include:-
var getCallerDetails = Class.create();
getCallerDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var currentDate = this.getParameter('sysparm_date');
var gdt = new GlideDateTime();
gdt.addDays(6);
if(currentDate>gdt.getDisplayValue()){
return true;
}else{
return false;
}
},
type: 'getCallerDetails'
});