Service Portal not rendering the knowledge blocks created on HR knowledge (u_kb_template_hr_knowledge) table.

dheeraaj
Giga Expert

Hi All,

Widget -- > myHR KB Article Page

Server Code snippet

t.text = new global.KBViewModel().getArticleContentBySysId(articleGR.getUniqueValue());

Script Include : KBViewModel   --- > overriding the KBViewModelSNC 

getArticleContentBySysId : function(articleSysId){   // OOB CODE
var gr = new GlideRecord("kb_knowledge");
var userId = gs.getUserID();
if(!articleSysId || !gr.get(articleSysId) || !gr.canRead())
return '';
this.knowledgeRecord = gr;
if(!this.tableName)
this.tableName = gr.sys_class_name + '';
if(!this.articleTemplateName)
this.articleTemplateName = this._knowledgeHelper.getArticleTemplateName(gr.sys_class_name) || '';
gs.info('article template name is:'+this.articleTemplateName);
gs.info('article content is:'+this.getArticleContent());
return this.getArticleContent();
},

However the article content is returning as empty when the article is created on  HR knowledge (u_kb_template_hr_knowledge) table and when knowledge blocks are applied to it.

But when the article is created on kb_knowledge table and when I apply the blocks to it, it is rendering correctly the KB blocks correctly.

Can anyone please help me what the issue is ?

 

Help is appreciated.

Regards,

Dheeraaj

1 ACCEPTED SOLUTION

Hi Ali,

 

I have figured out a way to do implement this and now its working super good. 

For anyone trying to implement the similar functionality, for the kb blocks to get rendered in the service portal for a different template other than the standard, the article along with the block should get populated in the KB Knowledge to Block History table.

 

Regards,

Dheeraaj

View solution in original post

9 REPLIES 9

Also one more question that I have is , I am trying to find  why  this.getArticleContent() in the code above is returning the value when the article is on Knowledge table and not returning the value when the article is on the HR knowledge table (u_kb_template_hr_knowledge)

 

Regards,

Dheeraaj

 

The actual logic for fetching the blocks are scripted in the KBBlockSNC script include. If you check this script, it is accessing an SNC.KnowledgeBlockSubstitution() where the rendering happens.

SNC means platform code and we do not have access into it. Maybe the function validates to check if the parent record is from kb_knowledge and only then it renders. I suggest you keep using kb_knowledge for rending knowledge blocks

	
    /**
    * Returns the article text content, with blocks substituted if blocks are enabled.
    */
    getArticleContent: function(knowledgeGR,userId,blocksArray) {
		var previewAsUser =  gs.nil(userId)!= true ? userId : gs.getUserID();
		if(!gs.nil(blocksArray))
			return new SNC.KnowledgeBlockSubstitution().substituteBlockOnDate(knowledgeGR.sys_id, knowledgeGR.text, previewAsUser,blocksArray);
			
		else if(this.hasBlocks(knowledgeGR))
			return new SNC.KnowledgeBlockSubstitution().substituteBlock(knowledgeGR.sys_id, knowledgeGR.text, previewAsUser);
		 else
				return knowledgeGR.text + '';
    },

Hi Ali,

 

I have figured out a way to do implement this and now its working super good. 

For anyone trying to implement the similar functionality, for the kb blocks to get rendered in the service portal for a different template other than the standard, the article along with the block should get populated in the KB Knowledge to Block History table.

 

Regards,

Dheeraaj

Please let me know how u implemented this. i am blocked on the same issue.

sai61
Kilo Explorer

@Dheeraj - please let me know how u implemented this.

this is not working for me for users with no role or group.