Maik Skoddow
Tera Patron
Tera Patron

find_real_file.png

 

Introduction

find_real_file.pngDocument Viewer is a platform feature that will enable users to view enterprise class documents inline within the platform attachment, instead of downloading it to the local device and then opening the documents with a locally installed viewer.

After setting table attribute use_document_viewer=true you are offered with an additional "view" option at "Manage Attachments" dialog. When clicking on "View" a browser windows opens and the selected document is rendered.

find_real_file.pngAs most of the important Microsoft Office formats (Word, Excel, Powerpoint) as well as PDF and images can be viewed this plugin is extremely helpful since in this way you can view files without having to have the corresponding program installed on your terminal device.

For more information please see the ServiceNow Documentation

 

 

Requirement

At table sys_attachment you only can download files, and it would be nice to have an additional option to view the attachment directly without downloading.

 

 

Solution

find_real_file.pngAs you know, it is not possible to open an Attachment record as each time you click on the row in the list view an attachment download will start.

Therefore, the only option we have is providing an additional UI Action "View" for the list view. Since it makes no sense to offer this action for a selection of multiple files, the best option is to introduce the command in the context menu (right-click on a record in the list view).

Downloading an attachment can be triggered by the following URL

http://<YOUR INSTANCE>.service-now.com/sys_attachment.do?sys_id=<ATTACHMENT SYS ID>


And opening the Document Viewer is as easy as adding another parameter to the download URL.

http://<YOUR INSTANCE>.service-now.com/sys_attachment.do?sys_id=<ATTACHMENT SYS ID>&view=true

 

Now we have everything to create a respective UI Action:

NameView
Tablesys_attachment
Clientchecked
List context menuchecked
onClickopenViewer()
Script
function openViewer() {
  var sysId = typeof rowSysId == 'undefined' ? gel('sys_uniqueValue').value : rowSysId;
  var url   = new GlideURL('sys_attachment.do');

  url.addParam('view', 'true');
  url.addParam('sys_id', sysId);
  g_navigation.open(url.getURL(), '_blank');
}
Comments
Murthy Ch
Giga Sage

Hi @Maik Skoddow 

Useful article

 

Thanks

 

Maik Skoddow
Tera Patron
Tera Patron

Nice to hear and thank you for the feedback!

Elias2
Tera Contributor

What I find is that the Document Viewer view function only works with record-level attachments. We have custom "File Attachment" fields for specific forms that would really benefit from the view function - is there a way to achieve this?

find_real_file.png

Tilly Penn
Tera Contributor

We do not have Document Viewer enabled, which means that Documents within KBs are downloaded, rather than opening within the platform.    My requirement is that I would like some documents to download (eg fillable forms), but some documents need to display in the Portal (eg Policy documents which we cannot allow to be changed). 

 

The links above didn't work for me (&view=true).  Everything still downloads.      Any ideas? 

 

SourabhJadhav
Tera Explorer

I want all attachments of supported file types ( Doc,xlsx,pdf,txt) to be viewed in the browser instead of forcing a download so that the users have a better experience. I have installed the plugins and added the use document viewer attributes as well. 

 

Can anyone help me on this? 

Peter Williams
Kilo Sage

i have the same situation where i need to have it displayed in the browser window

Version history
Last update:
‎09-04-2021 10:23 PM
Updated by: