Restrict user to select date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2022 08:27 PM
Hi All,
How to restrict a user to select a date for a catalog variable which is less than 3 days from today and does not falls on weekends.
I tried to do that by creating a date type field (o_expected_delivery_date) and catalog client script and script include but this is not working. Please help me. PFB the scripts I have tried and help me to rectify this.
onChange Catalog Client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var da = new GlideAjax('ClientDateTimeUtils');
da.addParam('sysparm_name','getDefaultEndDate');
da.getXMLWait();
var end_date = da.getAnswer();
alert ('abd'+ end_date);
if(g_form.getValue('o_expected_delivery_date') < end_date)
{
alert('Date should be After 3 days from current date time');
g_form.clearValue('o_expected_delivery_date');
return;
}
}
Script Include
ar ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDefaultEndDate: function() {
var startDate = gs.nowDateTime();
var addQuantity = this.getParameter('sysparm_quant');
var end_date = new GlideDateTime();
end_date.setDisplayValue(startDate);
end_date.addSeconds(259200);// Equivalent to 3 days
end_date = end_date.getDisplayValue();
return end_date;
},
});
onLoad client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var da = new GlideAjax('ClientDateTimeUtils');
da.addParam('sysparm_name','getDefaultEndDate');
da.getXMLWait();
var end_date = da.getAnswer();
alert ('abd'+ end_date);
if(g_form.getValue('o_expected_delivery_date') < end_date)
{
alert('Date should be After 3 days from current date time');
g_form.clearValue('o_expected_delivery_date');
return;
}
}
Regards,
Evan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 04:29 AM
@Evan
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
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
07-01-2022 02:24 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
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
01-03-2022 08:52 PM
Hi,
This must help:
I hope the answer helps, You can thank me by Marking the answer ✅ Correct or ???? Helpful.
Thanks,
MF Sohail Khilji.
LinkedIn > https://www.linkedin.com/in/mf-sohail-khilji/
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2022 11:42 PM
Hi there,
Is it an idea to use a schedule? A schedule with has mon-fri? Or maybe even to exclude holidays?
Let me know. Have working script which I can copy/paste here (got in draft for an article publishing soon), though first want to know more about your question.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 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
01-03-2022 11:49 PM
Hi Mark,
I want to restrict the end users to select that date that doesn't falls on Saturday or Sunday and should be at least more than 3 days from today.
If you have scripts to do that please share with me. It will be great help.
Regards
Evan