Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to remove standard from the article template in newyork?

Rahul Gupta
Tera Contributor

I wanted to remove the standard option from the select article template under knowledge category .

find_real_file.png

Please help me .!!

1 ACCEPTED SOLUTION

JayGervais
Kilo Sage

Hi @Rahul Gupta, I'm not sure if you are still having issues with this but I was also having trouble with this and managed to find a working solution. 

Within the ArticleTemplateUtil script include, you can add a method that overrides the getArticleTemplatesForKnowledgeBase method in the ArticleTemplateUtilSNC script.

Within the ArticleTemplateUtil script, the code is as follows:

var ArticleTemplateUtil = Class.create();
        ArticleTemplateUtil.prototype = Object.extendsObject(ArticleTemplateUtilSNC,{
			
			// script override to disable Standard KB template
			getArticleTemplatesForKnowledgeBase: 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'] = 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'
        });

Hopefully this helps.

Regards,

Jay

View solution in original post

10 REPLIES 10

Hi @JayGervais 

I tried the code you suggested but i keep getting this error. I am not sure what i am doing wrong. Please help. Thanks.

var ArticleTemplateUtil = Class.create();
ArticleTemplateUtil2.prototype = Object.extendsObject(ArticleTemplateUtil2SNC,{
	
		// script override to disable Standard KB template
			getArticleTemplatesForKnowledgeBase: 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'] = 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'
        });
	
// My original code starts here
getFieldsForTemplate: function(){
		var template = this.getParameter("sysparm_template");
		var fields = this.getFieldsDataForTemplate(template);
		var result = {
			fields: fields,
			template: template
		};
		return JSON.stringify(result);
	},

	getFieldsDataForTemplate: function(template){
		var fields = [];

		if(template == 'kb_knowledge'){
			fields.push( {
				field: '',
				type: 'HTML'
			});
			return fields;
		}

		var gr = new GlideRecord('kb_article_template_definition');
		gr.addQuery('article_template.child_table',template);
		gr.addActiveQuery();
		gr.orderBy('order');
		gr.query();

		while(gr.next()){
			var collapsible, collapsed, collapse_type = gr.getValue('collapsible');
			if(collapse_type == 'expanded'){
				collapsible = true;
				collapsed = false;
			} else if(collapse_type == 'collapsed') {
				collapsible = true;
				collapsed = true;
			} else {
				collapsible = false;
				collapsed = false;
			}
			fields.push( {
				field: gr.getDisplayValue('column_label'),
				type: gr.getDisplayValue('column_type'),
				column: gr.getValue('table_column'),
				collapsible: collapsible,
				collapsed: collapsed,
				heading_style: gr.getDisplayValue('heading_style'),
				field_style: gr.getDisplayValue('field_style'),
				preview_text: gr.getValue('u_preview_text'), //Added to see the Preview Text on the kb_knowledge_create_template_preview ui macro
			});
		}

		return fields;
	},
	
	type: 'ArticleTemplateUtil'
});

 

Hey there, 

What error are you getting and where did you add the code script?

Cheers,

Jay

Thanks @JayGervais !!

This helped !

urmilla
Kilo Guru

Hi, 

We had the same requirement, we could remove it from the ui for a particular knowledge base however how to achieve the same for the workspace view.

 

Thanks,

UD

Hello Urmilla,

 

I have the same requirement to remove Standard from particular knowledge base but above script does for all all.  How did you manage?  please advise. 

 

Thanks,

Gita