- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2022 11:18 PM
I have a date field in a catalog item. It should be restricted within earliest 7 working days from now, latest 3 month from today. Please help on how to implement this
Thanks!
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2022 04:29 AM
I completed it with UI policy
Date relative before 7 days from now or relative after 3 months from now -> Error message will be displayed using Run Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2022 11:35 PM
Hi,
so it should be either within 7 working days from now or 3 month from today?
can you explain this part
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2022 11:49 PM
It should be both -> allow the previous 7 working days from now (Eg : today is 21/02/2022 and should allow until 10/02/2022) and latest 3 months from today. And the other dates should be disabled (if possible, for a better experience)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2022 12:10 AM
Hi,
you will have to use onChange client script + GlideAjax for this
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2022 12:10 AM
Hi
You can use below catalog client script and script include for that.
Client Script:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var checkDate=new GlideAjax('validateDate');
checkDate.addParam('sysparm_name','checkDate');
checkDate.addParam('sysparm_date',newValue);
checkDate.getXML(checkDateFun); //callback function
function checkDateFun(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer=='false'){
g_form.clearValue('date');
}
}
}
Script Include:-
var validateDate = Class.create();
validateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkDate:function(){
var SevenDays=new GlideDateTime();
SevenDays.addDays(-7);
var threeMonths=new GlideDateTime();
threeMonths.addMonthsLocalTime(3);
var getDate=new GlideDateTime(this.getParameter('sysparm_date'));
if(getDate>=SevenDays && threeMonths>=getDate)
{
return true;
}else{
return false;
}
},
type: 'validateDate'
});
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Gunjan Kiratkar
Consultant - ServiceNow, Cloudaction
Rising Star 2022