Hi @Dr Atul - LNG  I am writing this script on on change client script. This is working but when we save the form or submit the valid to is still changing and getting the form saved.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var validityField = 'valid_to';
   var onYearValidity = new Date(new Date().setFullYear(new Date().getFullYear() + 1));
var newValidity = new Date(newValue);

   if(newValidity > onYearValidity) {
      // g_form.clearValue(validityField);
       g_form.showErrorBox(validityField,'Valid to date must be within a year from today');
   } else {
       g_form.hideErrorBox(validityField);
   }

}

Hi @Atchutaram 

 

This is my weak area :(. I am not a developer. 

 

@Jaspal Singh  @Community Alums any help here.

****************************************************************************************
Regards
Dr Atul G. - Learn N Grow Together ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
******************************************************************************************

View solution in original post

Thank you @Dr Atul - LNG  for your assistance, i am also posting this as one more question with code. Thank you very much for extending the help.

Not applicable

@Dr Atul - LNG thanks 👍

 

 

Hi @Atchutaram ,

 

There are 2 dates here one is article created date and another one is today's date so which of this 2 dates do you want to limit it to 1year ?

 

If it's today's date then you can simply do it with UI policy using relative filter. If it's created (or published date) you have to use Client script and check if the date selected falls within the 365days since publish or created. 

 

I hope this helps...

 

Please see the script I posted on the other post you submitted - https://www.servicenow.com/community/developer-forum/restrict-knowledge-article-valid-to-field/td-p/...


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni