Attachments don't get displayed in the new portal (Helsinki)

Miryana
Tera Contributor

Hi all,

I found out that in the new Service Portal attachments in knowledge articles just don't get displayed (I have Display Attachments to true in the article). They do show up in the Knowledge homepage. I am not sure if I am doing something wrong, missing an option or this is the intended functionality but any answer will be appreciated. If this is the intended functionality of the new portal - why and do I have to rewrite the widget to make it work?

1 ACCEPTED SOLUTION

brett_karl
ServiceNow Employee
ServiceNow Employee

Hi Miryana,


        There was currently only a ticket attachment widget in Service Portal. I've attached a completed widget for you to use (xml record to import). As well as placed the code below for others to examine. The widget will look to see if there are attachments associated with the knowledge base article and if the "display attachments" checkbox has been checked. Please let me know if you have any questions.



Body HTML Template


<div class="panel panel-{{options.color}} b kbattach" ng-show="data.theArticle">


  <div class="panel-heading"> <h4 class="panel-title" ng-bind="::options.title">


      <fa ng-if="::options.glyph.length" name="::{{options.glyph}}" class="m-r-sm" /></h4>


  </div>


  <div class="panel-body">


      <div ng-repeat="list in data.attachments" style="margin-bottom: 1em;">


          <a ng-href="/sys_attachment.do?sys_id={{list.sys_id}}">{{list.file_name}}</a>


      </div>


      <div ng-show="(data.attachments).length < 1" style="margin-bottom: 1em;">


          There are currently zero attachments


      </div>


  </div>


</div>



Server Script


data.theArticle = false;


var theSysID = $sp.getParameter('sys_id');




var gr = new GlideRecord("kb_knowledge");


gr.addQuery('sys_id', theSysID);


gr.addQuery('display_attachments', true);


gr.query();


while (gr.next()) {


  var display_attachments = gr.display_attachments;


}


data.theArticle = display_attachments;




var attachments = [];


var attachdata = new GlideRecord("sys_attachment");


attachdata.addQuery('table_name', 'kb_knowledge');


attachdata.addQuery('table_sys_id', theSysID);


attachdata.query();


while (attachdata.next()) {


  var attach = {};


  attach.file_name = attachdata.file_name.getDisplayValue();


  attach.sys_id = attachdata.getValue('sys_id');


  attachments.push(attach);


}


data.attachments = attachments;


View solution in original post

7 REPLIES 7

Hi @brett.carl, 

Is there any way that we can entirely remove the attachment widget in case a KB article has no attachment? i.e., instead of showing the message 'There are currently zero attachments', i want to remove the entire attachment widget from the page. Could you please advise me how this can be achieved? 

Dale Hynes
Kilo Sage

We've upgraded to Helsinki Patch 5 and the attachment are displayed and handled OK now. I have removed the 'temporary' attachments widget from our kb_article page and it's all good.



Thanks to all for advice on the workaround.



D.


pagdenl
Giga Expert

Question on this?  We are having issues with attachment not appearing if a user adds an ess user to a record, and when the ess user who is redirected to the portal, the attachment is not showing.  The ticket attachment widget is on the ticket page.