- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 03:16 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 04:42 AM
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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 03:19 AM
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 03:52 AM
Hello,
This is good for client Script, But I need it for business rule
Thanks,
B Siva Teja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 04:42 AM
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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 04:50 AM
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/