Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Display Attachments in Knowledge Articles

MeganCox
Tera Contributor

Is there any way to hide a PNG from the attachments list of a knowledge article? For example, we have a policy that is a PDF that we have attached to a knowledge article. We also put an image in the article, and now we can see both on the right side of the knowledge article. I see in the article itself, there's a display attachments checkbox, but if I remove that, I lose the PDF as well. 

 

Any suggestions? It's a policy, so I don't really want to convert it from a PDF to a PNG to avoid.

 

 

MeganCox_0-1758562343651.png

 

 

1 ACCEPTED SOLUTION

Paul Kunze
Tera Guru

Hi, you can customize the widget and Angular provider where the attachments are displayed and hide all png files using an ng-if condition.

 

Here is how you can do it:

  1. Duplicate the Angular Provider "spAttachmentManager" with a new name like "spAttachmentManagerNoPng", direct link: /sp_angular_provider.do?sys_id=06e836f0d722120023c84f80de6103a1
  2. Add this in line 7: ng-if="!attachment.file_name.endsWith(\'.png\')"
  3. Clone the widget "Knowledge Attachments" (kb-attachments), direct link: /sp_config?id=widget_editor&sys_id=405cf5910ba832004ce28ffe15673aff
  4. In line 2 of the cloned widget, replace the html tag "sp-attachment-manager" with "sp-attachment-manager-no-png"
  5. In your cloned widget, add the duplicated provider in the Related List:
    PaulKunze_0-1758638394271.png
  6. In Page Designer, open your KB Article page (for example "kb_article_view") and replace the "Knowledge Attachments" widget with your new "Knowledge Attachments Custom" widget
    PaulKunze_1-1758638904988.png

     

  7. Reload the page in Service Portal, you are done! (I kept both widgets here for illustration purposes)
    PaulKunze_3-1758639081758.png

     

View solution in original post

2 REPLIES 2

Paul Kunze
Tera Guru

Hi, you can customize the widget and Angular provider where the attachments are displayed and hide all png files using an ng-if condition.

 

Here is how you can do it:

  1. Duplicate the Angular Provider "spAttachmentManager" with a new name like "spAttachmentManagerNoPng", direct link: /sp_angular_provider.do?sys_id=06e836f0d722120023c84f80de6103a1
  2. Add this in line 7: ng-if="!attachment.file_name.endsWith(\'.png\')"
  3. Clone the widget "Knowledge Attachments" (kb-attachments), direct link: /sp_config?id=widget_editor&sys_id=405cf5910ba832004ce28ffe15673aff
  4. In line 2 of the cloned widget, replace the html tag "sp-attachment-manager" with "sp-attachment-manager-no-png"
  5. In your cloned widget, add the duplicated provider in the Related List:
    PaulKunze_0-1758638394271.png
  6. In Page Designer, open your KB Article page (for example "kb_article_view") and replace the "Knowledge Attachments" widget with your new "Knowledge Attachments Custom" widget
    PaulKunze_1-1758638904988.png

     

  7. Reload the page in Service Portal, you are done! (I kept both widgets here for illustration purposes)
    PaulKunze_3-1758639081758.png

     

Thank you so much! This worked great!