Knowledge Article Templates Preview?

Eran Spira1
Tera Contributor

Hi guys!

I've created a few KM Article Templates. When going through the new article creation wizard (in NY), I see the template fine however, each of the HTML fields on the preview are filled with lorem ipsum text. The text doesn't appear once the article is selected and in edit more -- only in the preview view.

Does anyone know if we can edit that text on the preview page?

find_real_file.png

6 REPLIES 6

Brandt3
Mega Contributor

There is no Out Of The Box way to achieve this. However, a close inspection of how this page works reveals that the solution can be customised to work at the cost of potential upgrade errors on 3 records. If recorded this shouldn't really be an issue as you can always reapply the customisation fairly easily. 

To make these changes you can apply the attached updateset or follow the below instructions (link will need to be changed for your instance). Note: The update set has comments to outline where changes are made for future reference.

Overview of what is changed:

  1. UI Page: kb_knowledge_create
  2. UI Macro: kb_knowledge_create_template_preview
  3. Script Include: ArticleTemplateUtil
  4. Field added to table: kb_article_template_definition

Navigate to the UI Page "kb_knowledge_create".

  • In the HTML section replace line 3 with the following, this imports ngSanitise so we can embed the html code for the preview:
  • <g:requires name="scripts/angular_1.5.11/angular.min.js" inline="true"/>
    <g:requires name="scripts/angular_1.5.11/angular-sanitize.min.js" inline="true"/>

In the Client Script section replace line 3 to use ngSanitize in the UI Page app 

    • var app = angular.module("createKnowledge",['ngSanitize']);

Navigate to the UI Macro "kb_knowledge_create_template_preview". This macro is called in the previous page. This is what controls the preview window.

  • Replace line 30 of the XML with the following. The removes the random lorem ipsum text that you see and replaced it with a custom fields text (which we will create next).
  • <div ng-bind-html="field.preview_text"></div>

Navigate to the "kb_article_template_definition" table and add a HTML field with the value "u_preview_text". (you can give the label any value).

I order to use this new field in the UI Page and UI Macro we've just modified, there is a script include to update. The UI Macro calls a script include called "ArticleTemplateUtil". In turn this extends a read-only script include called "ArticleTemplateUtilSNC". The UI Page calls a function in this script include that returns an array of objects for each field in the preview. We can copy and paste the function being called in ArticleTemplateUtilSNC to the ArticleTemplateUtil script and add one modification to it to add the "u_preview_text" field in the returned object.

Paste the following script into the "ArticleTemplateUtil" in a newline after line 2. There is a comment where the code addition has been added.

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'), //This is the new line we've added
			});
		}

		return fields;
	},

 

Congrats! Preview Text can now be added to each definition on the Article template.

 

Hope this helps!

Michael Scepano
Tera Contributor

In Vancouver you can edit the template text - but it only populates on this new preview mode. Will not show anything on the legacy new record page.