- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2016 07:41 AM
Anyone setup a script/scheduled job to kick off the Approval Retire Workflow when the valid to date has been reached? If so, could you provide the script and/or steps involved?
Thank you in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2016 07:48 AM
Hi Danielle,
It's actually pretty simple
/*
* The use case is "we would like to automatically retire the articles" (by default ServiceNow doesn't do anything with the valid_to date).
* Please find below (and attached), the script I used. The script would be a scheduled job and of course you can customize it
*
* Impact on performance: Low
* Upgradeability: No risk until ServiceNow is updating the knowledge management (a potential v4 one day)
*/
/*
* This script should be used as a Scheduled Job outside of business hours
*/
(function () {
//Query the published and expired Knowledge articles
var knowledge_article = new GlideRecord('kb_knowledge');
knowledge_article.addQuery('workflow_state', 'published');
knowledge_article.addQuery('valid_to', '<', gs.daysAgoStart(0));
knowledge_article.query();
while (knowledge_article.next()) {
if (knowledge_article.kb_knowledge_base.kb_version == "3") {
//Use the baseline API (KM v3) to retire the articles using the workflow of the Knowledge base
new KBWorkflow().startWorkflow(knowledge_article, "retire_workflow");
} else if (knowledge_article.kb_knowledge_base.kb_version == "2") {
//Use the knowledge v2 retirement
knowledge_article.workflow_state = 'retired';
}
knowledge_article.update();
}
})();
Best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2016 07:48 AM
Hi Danielle,
It's actually pretty simple
/*
* The use case is "we would like to automatically retire the articles" (by default ServiceNow doesn't do anything with the valid_to date).
* Please find below (and attached), the script I used. The script would be a scheduled job and of course you can customize it
*
* Impact on performance: Low
* Upgradeability: No risk until ServiceNow is updating the knowledge management (a potential v4 one day)
*/
/*
* This script should be used as a Scheduled Job outside of business hours
*/
(function () {
//Query the published and expired Knowledge articles
var knowledge_article = new GlideRecord('kb_knowledge');
knowledge_article.addQuery('workflow_state', 'published');
knowledge_article.addQuery('valid_to', '<', gs.daysAgoStart(0));
knowledge_article.query();
while (knowledge_article.next()) {
if (knowledge_article.kb_knowledge_base.kb_version == "3") {
//Use the baseline API (KM v3) to retire the articles using the workflow of the Knowledge base
new KBWorkflow().startWorkflow(knowledge_article, "retire_workflow");
} else if (knowledge_article.kb_knowledge_base.kb_version == "2") {
//Use the knowledge v2 retirement
knowledge_article.workflow_state = 'retired';
}
knowledge_article.update();
}
})();
Best regards,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2018 02:44 AM
Hi david where this script has to bee written ??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-12-2021 12:30 AM
I have this requirement but did not work for me. Please help.