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

Sorry, I double checked it in my PDI, that page knowledge_home_launcher.do is back-end code. Unfortunately, there's no way to remove Create an Article button.

Any update on this?

If I have answered your question, please mark my response as correct and/or helpful.

Thank you very much

Cheers
Alberto

I guess I don't feel comfortable marking "It can't be done" as the correct answer. I was hoping someone else might have another answer.  I understand that this may be the case but was leaving open with the hope of another answer or confirmation. 

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

Thank you for this great idea.  Please excuse my lack of experience.  Where do I find the ArticleTemplateUtil script?  I looked in UI Scripts and Client Scripts.

 

Also, I have no experience coding in Ajax, how would I include the Base script ArticleTemplateUtilSNC?

 

Thank you for your help and patience.