Access to attachments

sarahjantz
Tera Expert

Good morning!

 

We have a couple of catalog items that require attachments. We have included a link to these attachments in some email notifications via mail script. One of the new scenarios I have created sends this email to users that aren't licensed in ServiceNow and they aren't able to access these attachments. Those of us who are licensed have the document download in the browser, but the unlicensed users are looped back to the service portal. Is there a way to change this so anybody with the link can access the document?

2 REPLIES 2

Robbie
Kilo Patron
Kilo Patron

Hi @sarahjantz,

 

There sure is. See the below link that discusses how it can be achieved - basically, you have to write some code in an email script.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

Link where Ramesh and Drew get the credit. Here's the key code:

 

//These are the sys_ids of the attachments that you want to attach to the email.  You can find the sys_id by right-clicking the attachment on the attachment table and copying the sys_id.
var myStringArray = "57a856841ba937007b1ca7d4bd4bcb45,eba856841ba937007b1ca7d4bd4bcb46";

//This field wasn't used so I commented it out
//var att =[];

//Current.Instance returned undefined for me in my logging.  I attached both of my attachments to the email notification that I wanted to use.  Then I went to the sys_attachments table and found both of my attachments.  For those attachments it showed that the table sys ID was 3d68b54c1b2937007b1ca7d4bd4bcb47 so I substituted the variable sys for that sys_id.
//var sys = current.instance;
var sys = "3d68b54c1b2937007b1ca7d4bd4bcb47";

//This queries the sys_attachment table for all attachments where the table_sys_id is the sys_id you used above.
var grSysAtt = new GlideRecord('sys_attachment');
grSysAtt.addQuery('table_sys_id',sys);
grSysAtt.query();
while(grSysAtt.next()) {
var asys = grSysAtt.sys_id; 

//This if statement checks the attachments that you used in myStringArray and makes sure that it only grabs those attachments.
if(myStringArray.indexOf(asys)>=0){
var content = new GlideSysAttachment().getContentStream(grSysAtt.sys_id);
new GlideSysAttachment().writeContentStream(current, grSysAtt.getValue('file_name'), grSysAtt.getValue('content_type'), content);
gs.log("test name" + grSysAtt.getValue('file_name'));
}
}

 

The sys_id of the attachment would be different each time, so I don't see how I could include that in a script. To clarify, I'm looking for a way to attach the attachment(s) specific to the current record in a fashion that unlicensed users can view the attachment. It is currently providing a download link, but it only works for licensed users.