Show latest published version of the article in KB View page

Nitin Kumar2
Kilo Contributor

Hi,

When a user tries to see the article in kb_view he is getting displayed the latest version of the article irrespective of it's state ie., draft, rejected etc., which is not the correct thing. We would like to display the latest published version of the article.

Thanks

find_real_file.png

6 REPLIES 6

shloke04
Kilo Patron

Hi,

 

This is controlled via Script Include named "KBViewModelSNC" where the function called "findLatestVersion" is used to display the knowledge versions. This functions then again calls another Script include named "KBVersioningSNC" where the function getLatestAccessibleVersion is called where there is no condition mentioned to display only published articles. see the screenshot below:

 

find_real_file.png

 

In order to change this behavior you need to modify the script include named "KBVersioning" to override the KBVersioningSNC script include behavior and to display only published articles.

 

Hope this help. Please mark the answer as helpful/correct based on impact.

 

Regards,

Shloke

  

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi,

 

If your query is resolved, kindly mark the answer as correct and close the thread.

 

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi Shloke,

I was looking to do the same thing, and your suggestion was incredibly helpful. Thank you!

As a heads up to anyone else looking into doing this, I did also need to add the following code for the

getLatestVersionByNumber function to the KBVersioning script include, otherwise the permalink stopped working correctly.
kdettman_0-1698935272649.png

 

Thanks,

Kristen

javier_moral
Tera Contributor

Hi,

As of Utah Patch 7b this is still not fixed so I redefined these two functions in KBVersioning:

 

var KBVersioning = Class.create();

KBVersioning.prototype = Object.extendsObject(KBVersioningSNC, {
	/**
 	* Get latest *published* version of the article this user have access to
 	*
 	* @Param String articleNumber
	* @return GlideRecord record
 	**/
	getLatestAccessibleVersion: function(articleNumber, ignoreOutdated){
        var gr = new GlideRecordSecure(this.KB_KNOWLEDGE);
        gr.addQuery('number', articleNumber);
        if (ignoreOutdated) {
            gr.addQuery('workflow_state', '!=', 'outdated');
        }
		//Search only PUBLISHED items
		gr.addQuery('workflow_state', '=', 'published');

        gr.orderByDesc('version.sys_created_on');
        gr.setCategory('homepage');
		gr.query();
        if (gr.next()) {
            var record = new GlideRecord(this.KB_KNOWLEDGE);
            record.get(gr.getUniqueValue());
            return record;
        } else
            return false;
	},

	/**
 	* Get latest *published* version of the article this user have access to
 	*
 	* @Param String articleId
	* @return GlideRecord record
 	**/
	getLatestAccessibleVersionFromId: function(articleId){
		gs.info("JM articleId  "+articleId);
		var gr = new GlideRecordSecure(this.KB_KNOWLEDGE);
		gr.addQuery("article_id",articleId);

		//Search only PUBLISHED items
		gr.addQuery("workflow_state","=","published");
		
		gr.orderByDesc("version.sys_created_on");
		gr.setCategory("homepage");
		gr.query();
		if(gr.next()){
			var record = new GlideRecord(this.KB_KNOWLEDGE);
			record.get(gr.getUniqueValue());
			return record;
		}
		else
			return false;
	},
    type: 'KBVersioning'
});

 

Javier Moral