- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2017 12:23 AM
Hi,
I have a request for showing a document revision (can be a pdf) in a new window. Currently I have developed this UI action where I first find the revision for the document and then find the attachment in the sys_attachment table. But using this code will always download the document found to the users pc.
Any suggestions how I can just show the document in a new window and prevent it from downloading to the users pc ? Or is it just standard servicenow that it will always download to the users pc ?
var docnumber = current.getValue('number');
var sysid = current.sys_id.toString();
var doc_name;
var doc_rev = new GlideRecord('dms_document_revision');
doc_rev.addQuery('document', sysid);
doc_rev.orderByDesc('sys_updated_on');
doc_rev.query();
if (doc_rev.next()){
var attach_sysid = doc_rev.getValue('sys_id');
var doc_attach = new GlideRecord('sys_attachment');
doc_attach.addQuery('table_sys_id', attach_sysid);
doc_attach.setLimit(1);
doc_attach.query();
if(doc_attach.next()){
var id = doc_attach.getValue('sys_id');
gs.addInfoMessage('Document found');
action.setRedirectURL('sys_attachment.do?sys_id=' + id);
} else {
gs.addInfoMessage('Found no document');
action.setRedirectURL(current);
}
} else {
gs.addInfoMessage('Found no document');
action.setRedirectURL(current);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2017 01:16 AM
Hi Kim,
When you say to show attachment in a new window, what do intend to display? The attachment record in sys_attachment table cannot be opened as a record, it is a default behavior that the file gets downloaded when you open it.
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2017 12:58 AM
Hi Kim,
You can use UI action with below information
Client : True
Onclick : redirect()
Script:
function redirect(){
window.open('your url','_blank');
}
Hope this helps.
Regards
Ujjawal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2017 01:14 AM
Hi Ujjawal,
I tried that already but couldn't get it to work.
/Kim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2017 01:03 AM
Hi Kim,
I think view will work out but it will download. Which ServiceNow version are you using?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2017 01:13 AM
Hi Midhun,
Using Helsinki - what do you mean with view ?
/Kim