Automatically update "Valid To" of previous article version when a new draft is created
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
How to update "Valid To" date of the previous published version automatically when a new draft is created
to make sure previous version does not go to pending retirement avoiding multiple published versions or accidental retirement of the latest version
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Hey @vivek11
You can handle this requirement by updating the previous published version at the time a new draft is created, instead of relying on retirement workflows.
Approach (Business Rule)
Create a Before Insert Business Rule on kb_knowledge:
Condition:
- workflow_state = draft
Script:
(function executeRule(current, previous) {
if (current.workflow_state != 'draft')
return;
var kb = new GlideRecord('kb_knowledge');
kb.addQuery('number', current.number);
kb.addQuery('workflow_state', 'published');
kb.addQuery('sys_id', '!=', current.sys_id);
kb.orderByDesc('version');
kb.query();
if (kb.next()) {
kb.valid_to = new GlideDateTime(); // expire previous version
kb.update();
}
})(current, previous);
Why this works
Ensures only one active published version
Prevents previous version from going into Pending Retirement
Avoids accidental retirement of the latest version
Uses Valid To (recommended lifecycle control instead of forcing state change)
Notes
- Do not set previous version to Retired (this triggers workflows and can cause issues)
- number links all versions of the same article
- This approach keeps older versions for history but makes them inactive
*********************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb
