Restrict user to select date

Evan2
Kilo Guru

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

 

 
14 REPLIES 14

@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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sohail Khilji
Kilo Patron
Kilo Patron

Hi,

 

This must help:

https://community.servicenow.com/community?id=community_question&sys_id=189ffae9db58dbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=75309be5dbdcdbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=60118e4ddba2a700656a5583ca96...

 

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....

LinkedIn - Lets Connect

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

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