The CreatorCon Call for Content is officially open! Get started here.

Retire translated versions when english article is retired

Abhishek Akundi
Tera Contributor

I created a Business Rule that retires translated articles when the English version is retired. It works fine if there's a translation for the same version of the English article.

But here's the problem:
If I retire the latest English version (like v3) and it doesn't have a translation, the rule doesn't retire older translated versions (like v1 or v2). Those older translations stay active.

What I need is:
Whenever I retire the latest English version, all translations from any version should be retired — even if they were created for older versions.

Below is the business rule

 

(function executeRule(current, previous /*null when async*/) {
    var translations = new GlideRecord('kb_knowledge');
    translations.addQuery('translated_from', current.sys_id);
    translations.addQuery('workflow_state', '!=', 'retired');
    translations.query();

    while (translations.next()) {
        translations.workflow_state = 'retired';
        translations.update();
    }
})();
1 REPLY 1

M Iftikhar
Giga Sage

@Abhishek Akundi ,

 

You need to Identify all English versions of the same article, and then retire translations of all those versions.

Below updated Script might work for your use case:

(function executeRule(current, previous /*null when async*/) {
    var englishVersions = new GlideRecord('kb_knowledge');
    englishVersions.addQuery('article_number', current.number);
    englishVersions.addQuery('language', 'en'); 
    englishVersions.query();
    var englishIds = [];
    while (englishVersions.next()) {
        englishIds.push(englishVersions.sys_id.toString());
    }

    // Find and retire all translations linked to any of those English versions
    var translations = new GlideRecord('kb_knowledge');
    translations.addQuery('translated_from', 'IN', englishIds);
    translations.addQuery('workflow_state', '!=', 'retired');
    translations.query();

    while (translations.next()) {
        translations.workflow_state = 'retired';
        translations.update();
    }

})();

 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.