Is there a way to restrict KB article to only published versions should be visible on portal ?

1_DipikaD
Kilo Sage

Hi All,

 

It appears that on the service portal view of the knowledge base non approved versions appear as an updated version available to view in the service portal view of the knowledge base. Is there a way to restrict this to only published versions? As per shown in the below image 13.02 is the updated version but in draft state meanwhile 13.0 is published version. I need to show only publish version of KB and unpublished version of KB article should not be visible. Please let me know how can I achieve it ?

 

Thank You

 

 

1_DipikaD_0-1769068990337.png

 

1 REPLY 1

vaishali231
Giga Guru

hey @1_DipikaD 

In Service Portal, the knowledge article shows An updated version of this article is available even when the newer version is still in Draft state.
Example:

Version 13.0 - Published

Version 13.02 - Draft
Even though 13.02 is not approved, the portal still shows it as an updated version.

Root Cause

The Knowledge Article widget uses the following logic:

kbViewModel.getLatestAccessibleVersionFromId()


This method returns the latest accessible version, not the latest published version.
So if the logged-in user has access to Draft articles (admin, kb_writer, etc.), the Draft version is treated as the latest one and triggers the banner.

Solution

The fix is to replace this logic and explicitly check for a newer Published version only.

Replace the existing code:

vaishali231_0-1769072882972.png

 

var latest = kbViewModel.getLatestAccessibleVersionFromId(knowledgeRecord.article_id);
var newVersionAvailable = !gs.nil(latest) &&
(latest.getValue('version') != knowledgeRecord.getValue('version'));


With the following:

var newVersionAvailable = false;

var gr = new GlideRecord('kb_knowledge');
gr.addQuery('number', knowledgeRecord.number);
gr.addQuery('workflow_state', 'published');
gr.addQuery('version', '>', knowledgeRecord.version);
gr.query();

if (gr.hasNext()) {
newVersionAvailable = true;
}


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