Knowledge Module - Create Article button shows Standard template despite standard template being inactive

litchick10
Tera Guru

When users select the "Create Article" button, they must select the knowledge base and then the appropriate template.  If they click the left hand menu "Create New" the active templates are shown. 

We have removed Standard from the interceptors so we can use a "Default" template instead.  However the "Standard" template is still shown on the "Create Article" template options. (see below). How do I deactivate/remove it as an option

find_real_file.png

Alternately, could we just make the "Create Article" button default to the same screen as the "Create New" menu option

find_real_file.png

1 ACCEPTED SOLUTION

amaradiswamy
Kilo Sage

Hi @litchick10 ,

I found a way to fix this. If you are still looking for a possible way then you may try below.

 

1. Open "ArticleTemplateUtil" script include and paste the below code.

var ArticleTemplateUtil = Class.create();
        ArticleTemplateUtil.prototype = Object.extendsObject(ArticleTemplateUtilSNC,{
			
		getTemplatesDataForKB: function()
			{
		var kbId = this.getParameter("sysparm_kbid");
		var templates = this.getCanContributeTemplatesListCustom(kbId);		
		var result = {
			templates: templates,
			kb: kbId
		};
		return JSON.stringify(result);
			},
			getCanContributeTemplatesListCustom: function(kbId){
		var kbGr = new GlideRecord('kb_knowledge_base');
		if(kbGr.get(kbId) && SNC.KnowledgeHelper.canContribute(kbGr))
			return this.getArticleTemplatesForKnowledgeBaseCustom(kbId,false);
		else
			return {};
	},
	getArticleTemplatesForKnowledgeBaseCustom: function(kbId, addNames){
		var gr = new GlideRecord('kb_template_m2m_knowledge_base');
		gr.addQuery('kb_knowledge_base',kbId);
		gr.query();

		var templates = {};
// 		if(addNames)
// 			templates['kb_knowledge'] = gs.getMessage('Standard');
// 		else
			//templates['kb_knowledge'] = true;
		
		if(!gr.hasNext()){
			var template = new GlideRecord('kb_article_template');
			template.addActiveQuery();
			template.query();
			while(template.next()){
				if(!addNames)
					templates[template.child_table] = template.getDisplayValue('article_template');
// 				else
// 					templates[template.child_table] = true;
			}
			return templates;
		}
		else {
			while(gr.next()){
				if(gr.kb_article_template.active){
					if(!addNames)
						templates[gr.kb_article_template.child_table] = gr.kb_article_template.getDisplayValue();
					else
						templates[gr.kb_article_template.child_table] = true;
				}
			}
		}
		return templates;
	},
        type: 'ArticleTemplateUtil'
        });

 

in "kb_knowledge_create" UI page and 60th line of client script is getting list of available templates via GlideAjax. So, I tried by overriding the method "getTemplatesDataForKB" in ArticleTemplateUtil script include as base system script include ArticleTemplateUtilSNC is readonly and protected.

 

You may tweak the code as just thought of sharing what I have tried for a similar use case

View solution in original post

11 REPLIES 11

Hi @litchick10 ,

 

ArticleTemplateUtil is available in System UI --> Script Includes.

find_real_file.png

we can't edit "ArticleTemplateUtilSNC" as it is protected and made read-only. That's why servicenow provided another script include "ArticleTemplateUtil" which we can modify as per our requirement.

 

If you look at "ArticleTemplateUtil" script include, it will call "ArticleTemplateUtilSNC" script include.

This worked perfectly, THANK YOU!!!