KB articles is to set the Valid To date one year from the Published date. it's working fine now . should not allow more than one year from publish date . How can we restrict.

skkkk
Giga Contributor

KB articles is to set the Valid To date one year from the Published date. it's working fine now . should not allow more than one year from publish date . How can we restrict.

1 ACCEPTED SOLUTION

This is done, Please test and let me know.



Steps to test



1) Create a new article and submit it. (Do not enter Published date now)


2) Click on publish button to publish the article. This will populate the published date and Valid To dates (Valid to is Published date + 1 year)


3) Try to change valid to > 1 year, you will get an error and user cannot change it.



Business rules



Set Valid To Upon Publish


(function executeRule(current, previous /*null when async*/) {


  // Add your code here


  var publishedDate = new GlideDateTime(current.published.getDisplayValue());


  publishedDate.addYears(1);


  current.valid_to = publishedDate.getDate();


})(current, previous);



Check Valid To


(function executeRule(current, previous /*null when async*/){


  // Add your code here


  var validDate = new GlideDateTime(current.valid_to.getDisplayValue());


  var publishedDate = new GlideDateTime(current.published.getDisplayValue());


  publishedDate.addYears(1);



  if(validDate > publishedDate){


  gs.addInfoMessage("You cannot select this date as Valid to");


  current.valid_to = previous.valid_to;


  current.setAbortAction(true);


  }


})(current, previous);



If this has answered your question, please mark my response as correct answer.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

23 REPLIES 23

Hi,



I tried and it worked for me. The system wont allow me to select a date in Valid to date which is greater than 1 year from the published date. Please see if you set it up as per screenshot.



find_real_file.png



Script as



find_real_file.png



(function executeRule(current, previous /*null when async*/) {


  // Add your code here


  var validDate = new GlideDateTime(current.valid_to.getDisplayValue());


  var publishedDate = new GlideDateTime(current.published.getDisplayValue());


  publishedDate.addYears(1);


  if(validDate > publishedDate){


  gs.addInfoMessage("You cannot select this date as Valid to");


  current.valid_to = previous.valid_to;


  current.setAbortAction(true);


  }


})(current, previous);





Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


skkkk
Giga Contributor

Same code i pasted on business rule . Still not working .


find_real_file.png


Have you kept this as a before update business rule on When to run tab?



Also can you show me a screenshot of value you are updating on valid to and published date.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


skkkk
Giga Contributor

It's not functioning ..




2.PNG1.PNG


Please enter a date after 03/22/18, The validation will be displayed only once you save, submit or update the record and it wont allow a user to save the value.



Please try it.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response