Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

How can I implement this condition to be valid once the user selects a variable field choice please?

Service_RNow
Mega Sage

Hi

Link Limit date selection in date field   has a UI policy part for limiting date selection possibly that would help & would be simplest one to set up.

Please mark reply as Helpful/Correct, if applicable. Thanks!

hi RamS,

i did it using ui policy but i didn't work properly

Hi Vellanki,

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