how to restrict the user not to select the date more than 6 months from today

vellanki divya
Kilo Guru

hi folks,

i have a catalog item varaible with the field type date  named "date''

i tried using ui policy but didn't fetch me the results. can you please help me out

 

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi Vellanki,

You can create a catalog client script onchange to do this. Here is the code and screenshot for reference. 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var gdt = new Date(newValue);


var currentDate = new Date();


currentDate.setDate(currentDate.getDate() + 180);


  if(gdt>currentDate) {


     alert("you cannot select date after 6 months");


  }


}

 

find_real_file.png

Kindly mark the answer as correct if this helps.

View solution in original post

8 REPLIES 8

Omkar Mone
Mega Sage

Hi 

Go through the below link :-

https://community.servicenow.com/community?id=community_question&sys_id=15658baddbd8dbc01dcaf3231f961936

asifnoor
Kilo Patron

Hi Vellanki,

You can create a catalog client script onchange to do this. Here is the code and screenshot for reference. 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var gdt = new Date(newValue);


var currentDate = new Date();


currentDate.setDate(currentDate.getDate() + 180);


  if(gdt>currentDate) {


     alert("you cannot select date after 6 months");


  }


}

 

find_real_file.png

Kindly mark the answer as correct if this helps.

Hi Vellanki,

Did you try the code that I have shared above? Using catalog client script, you can achieve this.

Mark correct if this works.

hi asifoor,

tq for your response.

well you took 30 days for each month and added 180...but there are some months with 31 and 28 too ..

how to deal with them