Service Portal Knowledge articles created using kb article templates are not displaying correctly in portal

Jaydeep1
Kilo Explorer

Hello,

I am currently working on the ServiceNow Portal and linking the Knowledge Base to the Portal. The knowledge base is linked and everything is working fine except when viewing articles created from the KB templates. When going into the view from the Portal, it only shows the short description, author, view count, and date. It does not show the Articles details at all. But in ServiceNow, it shows all the details. Please see attached screenshots:

Here is my code within the server script:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

var t = data;
data.kb_knowledge_page = $sp.getDisplayValue("kb_knowledge_page") || "kb_view";
var articleGR = GlideRecord("kb_knowledge");
articleGR.get($sp.getParameter('sys_id'));
var recordIsValid = articleGR.isValidRecord();
var canReadArticle = articleGR.canRead();
t.isvalid = recordIsValid && canReadArticle;

if (canReadArticle) {
articleGR.incrementViewCount(); // update sys_view_count immediately on kb_knowledge record
var art = new GlideRecord("kb_use");
if (art.isValid()) {
art.article = articleGR.getUniqueValue();
art.user = gs.getUserID();
art.viewed = true;
art.insert(); // kb_use records are aggregated to update sys_view_count nightly
$sp.logStat('KB Article View', "kb_knowledge", articleGR.getUniqueValue(), articleGR.short_description);
}

t.category = articleGR.getValue('kb_category');
t.sys_id = $sp.getParameter('sys_id');
t.showAttachments = false;
if (articleGR.display_attachments)
t.showAttachments = true;
t.categoryDisplay = articleGR.getDisplayValue('kb_category');
t.short_description = articleGR.getValue('short_description');
if (articleGR.getValue('article_type') == 'wiki')
t.text = GlideWikiModel().render(articleGR.getValue('wiki'));
else
t.text = articleGR.getValue('text');
t.sys_view_count = articleGR.getDisplayValue('sys_view_count');
t.author = articleGR.getDisplayValue('author');
t.publishedUtc = articleGR.getValue('published');
t.number = articleGR.getValue('number');
if (showStarRating())
t.rating = articleGR.getValue('rating');
t.direct = false;
if (articleGR.direct)
t.direct = true;

t.breadcrumbs = [{label: t.short_description, url: '#'}];
if (!articleGR.kb_category.nil()) {
var rec = articleGR.kb_category.getRefRecord();
while (rec.getRecordClassName() == "kb_category") {
t.breadcrumbs.unshift({label: rec.getDisplayValue(), url: '?id=kb_category&kb_category=' + rec.getUniqueValue()});
rec = rec.parent_id.getRefRecord();
}
}
t.breadcrumbs.unshift({label: gs.getMessage("Knowledge Base"), url: '?id=' + t.kb_knowledge_page});
}

function showStarRating() {
if (options.show_star_rating == "Yes")
return true;

if (options.show_star_rating == "No")
return false;

if (gs.getProperty("glide.knowman.show_star_rating", "true") != "true")
return false;

return gs.hasRole(gs.getProperty("glide.knowman.show_star_rating.roles"));
}

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Can someone please advise on if I need to add anything additional to the code or perform a workaround?

5 REPLIES 5

Bjoern3
Tera Guru

The KB0692733 workaround has an error in it. The first line is

if(articleGR.sys_class_name === 'kb_knowledge'){ // is not a template

but that does not work. Remove one "=" and the widget displays both regular articles and template ones. I guess the types don't match, but the Content does, so we need  == instead of ===.