Knowledge Base review date update

Ballela Siva Te
Tera Contributor

Hi Team,

 

We have created a field called review date in knowledge article. The review date should be updated when published date changes. For example if the published date is today review date should be six months to current date. Can you provide script which I can incorporate over business rule

 

Regards,

B Siva Teja

1 ACCEPTED SOLUTION

AndersBGS
Tera Patron
Tera Patron

Hi @Ballela Siva Te ,

 

Something like below should be able to do the trick:

(function executeRule(current, previous /* previous values from the form */) {

    // Get the published date from the current record
    var publishedDate = current.published_date; // Change 'published_date' to the actual field name

    // Check if the published date is populated
    if (publishedDate) {
        // Calculate the review date (6 months ahead)
        var reviewDate = new GlideDateTime(publishedDate);
        reviewDate.addMonthsLocalTime(6);

        // Set the review date in the appropriate field
        current.review_date = reviewDate; // Change 'review_date' to the actual field name
    }

})(current, previous);

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

View solution in original post

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Ballela Siva Te 

 

https://www.servicenow.com/community/developer-forum/how-to-set-due-date-using-client-script/m-p/168...

 

*************************************************************************************************************
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]

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

Hello,

 

This is good for client Script, But I need it for business rule

 

Thanks,

B Siva Teja

AndersBGS
Tera Patron
Tera Patron

Hi @Ballela Siva Te ,

 

Something like below should be able to do the trick:

(function executeRule(current, previous /* previous values from the form */) {

    // Get the published date from the current record
    var publishedDate = current.published_date; // Change 'published_date' to the actual field name

    // Check if the published date is populated
    if (publishedDate) {
        // Calculate the review date (6 months ahead)
        var reviewDate = new GlideDateTime(publishedDate);
        reviewDate.addMonthsLocalTime(6);

        // Set the review date in the appropriate field
        current.review_date = reviewDate; // Change 'review_date' to the actual field name
    }

})(current, previous);

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

In addition you see below code:

 

  // Get the published date from the current record
    var publishedDate = new GlideDate(); // Change 'published_date' to the actual field name

    // Check if the published date is populated
    if (publishedDate) {
        // Calculate the review date (6 months ahead)
        var reviewDate = new GlideDateTime(publishedDate);
        reviewDate.addMonthsLocalTime(6);

        // Set the review date in the appropriate field
        gs.log(reviewDate); // Change 'review_date' to the actual field name
    }

Which utilize current date (new glidedate) will give = 

2024-09-11 10:48:40

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/