Okay, right off the bat, I need to apologize for the terrible post title…I tried 😪
Having said that, let’s get straight to it. In this post, we’re going to explore a very simple trick that I learnt whilst working on a use case and wondered – man why didn’t Servicenow default this already?! Alright, without further ado, I am talking about introducing a download link in your list view for ticket attachments.
As you may have noticed in the list view, the download link gets rendered for incidents that have an attachment tied to the form. So how do I get this rad download link on my list?! I’m glad you asked.
Form Setup
For the purposes of this post, I will be setting this up on the incident form. First things first, create a URL type field called ‘Download Link’.
Now, the fun bit…you’re going to dynamically generate this link, if there exists an attachment for the incident in question.
Calculated Value
Configure dictionary on the ‘Download Link’ field, select ‘Advanced View’ in the related list. In the ‘Calculated Value’ tab, check the ‘Calculated’ field, which reveals a Calculation script. Key in the following script,
(function calculatedFieldValue(current) {
var table_sys_id;
var gr = new GlideRecord('sys_attachment');
if(gr.get('table_sys_id', current.sys_id)) {
table_sys_id = gr.sys_id+'';
}
else {
return '';
}
var downloadLink = 'https://devxxxxx.service-now.com/sys_attachment.do?sys_id='+table_sys_id;
return downloadLink;
})(current);
Styling the download link
I figured we needed to add a bit of zing to the link itself, right click the ‘Download Link’ field, select ‘Configuration Styles’.
Create a new style for the field, here’s my setup
Oh just a side note here, you need to have an icon pre-loaded (in this instance I’ve called it download_icon.png). I’m pasting the only CSS I’m using,
background-image: url('download_icon.png');
background-repeat: no-repeat;
background-size: 12px 12px;
and there you go folks, you’re very own download link,