Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Control Visibility of attachments of in KB Articles

Balakrishna_ABK
Tera Guru
dd.png
 
 
I want to show only pdfs attached in the article body not the jpg files in the portal of the knowledge article.
If I make display attachments false I am missing pdfs along with jpgs.
suggest better approach.
 

 

2 REPLIES 2

Tanushree Maiti
Giga Sage

You can create a user criteria . Add required user/role/group/company & add script using your logic.

Logic should be 

you need to check  current KB article's attachment in sys_attachment table and its Content Type .

If Content type  is pdf . it will not be accessible to user/group/role

else 

it would be visible .

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

lauri457
Tera Sage

Below is the method that will query the attachments. You can override this method in the KBViewModel script include to fit your requirements.

//global.KBViewModelSNC
	getAttachments: function () {
		var tableUtils = new TableUtils(this.tableName);
		var tn = tableUtils.getAllExtensions();
		var att = new GlideRecord("sys_attachment");
		att.addQuery("table_name", tn);
		att.addQuery("table_sys_id", this.knowledgeRecord.sys_id);
		att.orderByDesc("sys_created_on");
		att.setCategory('homepage');
		att.query();
		var attachments = [];
		while (att.next() && att.canRead())
			attachments.push({sys_id: att.sys_id + "", file_name: att.file_name + "", size: att.getDisplayValue("size_bytes") + "", state: att.getValue("state") + ""});
		return attachments;
	},