Show latest published version of the article in KB View page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 05:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 07:20 AM
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:
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2019 03:55 PM
Hi,
If your query is resolved, kindly mark the answer as correct and close the thread.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 07:27 AM - edited ‎11-02-2023 07:28 AM
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
Thanks,
Kristen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2023 07:13 AM
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