Set kb article valid to

Vijaykumar K
Tera Contributor

Hi all, i needed a help on update business rule on knowledge article table. So when ever user is trying to update valid to value then that date should be with in 1 yr from current date. Else abort the action. Pls help on how to achieve the same.

 

Thanks

1 ACCEPTED SOLUTION

Prashant16
Kilo Guru

Hi Vijay,

 

you can create a before insert/update Business rule with condition "Valid To" changes and add the below script:

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

    var currentDay =  new GlideDate();
    currentDay.addYears(1);

    if(current.valid_to > currentDay.getDate()){
        current.setAbortAction(true);
        gs.addErrorMessage("add a date with 1 year");
    }
    gs.info("checkdate"+currentDay.getDate());
})(current, previous);
 
If my answer helped you. Please mark my answer correct or helpful.
Regards,
Prashant

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Vijaykumar K 

 

We can set valid to on Knowledge base level and if a user want to change, you can set the UI policy for same. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

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
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG  thanks for the suggestion. But what will be the behaviour of existing kb articles validity if we enter Knowledge base validity now. 

Prashant16
Kilo Guru

Hi Vijay,

 

you can create a before insert/update Business rule with condition "Valid To" changes and add the below script:

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

    var currentDay =  new GlideDate();
    currentDay.addYears(1);

    if(current.valid_to > currentDay.getDate()){
        current.setAbortAction(true);
        gs.addErrorMessage("add a date with 1 year");
    }
    gs.info("checkdate"+currentDay.getDate());
})(current, previous);
 
If my answer helped you. Please mark my answer correct or helpful.
Regards,
Prashant