Is it possible to open a Knowledge Article direct to the attachment without opening the article?

Flitdog78
Giga Expert

As per the Subject - is the service able to open the pdf attached to the article directly within the viewer without downloading it?

Flitdog78_0-1691074546218.png

 

1 ACCEPTED SOLUTION

Riya Verma
Kilo Sage
Kilo Sage

HI @Flitdog78 ,

 

Hope you are doing great.

 

Yes, it is possible to open a Knowledge Article directly to the attachment without opening the article in ServiceNow.

 

1. Create a UI Action: Go to "System Definition" > "UI Actions" and create a new UI Action with the following settings:

                   Table: kb_knowledge (Knowledge Article table)

                    Action name: open_attachment_directly

                    Client: true

2. Navigate to "System Definition" > "UI Scripts" and create a new UI Script with the following code:

 

function openAttachmentDirectly() {
  var knowledgeSysID = g_form.getValue('sys_id'); // Get the current Knowledge Article's sys_id
  var attachmentSysID = g_form.getValue('u_attachment_field'); // Replace 'u_attachment_field' with the actual field name storing the attachment sys_id

  if (attachmentSysID) {
    var attachmentUrl = new GlideURL('sys_attachment.do');
    attachmentUrl.addParam('sys_id', attachmentSysID);
    attachmentUrl.addParam('sysparm_referring_url', 'kb_knowledge.do?sys_id=' + knowledgeSysID);
    window.open(attachmentUrl.getURL());
  } else {
    alert('No attachment found.');
  }
}

 

3. Add the UI Action to the form layout: Edit the form layout of the Knowledge Article table (kb_knowledge) and include the newly created UI Action, "Open Attachment Directly."

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

View solution in original post

9 REPLIES 9

Lauren Methena
Giga Guru

Yes. At the top of your article form/article template, where you see all your different settings and choices (i.e., KB#, knowledge base, category, Valid to date, etc.), you should see two check boxes - one for "Attachment link" and one for "Display attachments."

 

If you click "Attachment link" to turn it on, then when someone finds that article in the search results, the attachment will download or open instantly instead of opening the article. 

 

(I actually find this feature really annoying and we never use it, but I can see where it might be helpful for some things.)

 

Good luck! I hope this is helpful to you or answers your question.

Thank you very much for this @Lauren Methena,  much appreciated.  Yes this works great for most of our users, but we're trying to capture those who still don't like this method of downloading and opening attachments to articles.  (People eh?), so I think Riya's method should work once I'm able to test it.

Riya Verma
Kilo Sage
Kilo Sage

HI @Flitdog78 ,

 

Hope you are doing great.

 

Yes, it is possible to open a Knowledge Article directly to the attachment without opening the article in ServiceNow.

 

1. Create a UI Action: Go to "System Definition" > "UI Actions" and create a new UI Action with the following settings:

                   Table: kb_knowledge (Knowledge Article table)

                    Action name: open_attachment_directly

                    Client: true

2. Navigate to "System Definition" > "UI Scripts" and create a new UI Script with the following code:

 

function openAttachmentDirectly() {
  var knowledgeSysID = g_form.getValue('sys_id'); // Get the current Knowledge Article's sys_id
  var attachmentSysID = g_form.getValue('u_attachment_field'); // Replace 'u_attachment_field' with the actual field name storing the attachment sys_id

  if (attachmentSysID) {
    var attachmentUrl = new GlideURL('sys_attachment.do');
    attachmentUrl.addParam('sys_id', attachmentSysID);
    attachmentUrl.addParam('sysparm_referring_url', 'kb_knowledge.do?sys_id=' + knowledgeSysID);
    window.open(attachmentUrl.getURL());
  } else {
    alert('No attachment found.');
  }
}

 

3. Add the UI Action to the form layout: Edit the form layout of the Knowledge Article table (kb_knowledge) and include the newly created UI Action, "Open Attachment Directly."

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Hi @Riya Verma, you're an absolute star.  This is exactly what I was after, I can't test it due to security constraints and we're upgrading to Utah so freeze is in effect.  But this looks absolutely perfect.  Beautifully detailed instructions, what a great community.