We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Control Visibility of attachments of in KB Articles

Balakrishna_ABK
Kilo Sage
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
Tera Patron

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 Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

lauri457
Kilo Patron

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;
	},