Download attachment by passing file_name instead of sys_id

Ovin Detree
Kilo Explorer

We are able to download an attachment using the sys id by using the below URL in the web browser or postman.

https://servicenow-instance.ourdomain.com/sys_attachment.do?sys_id=21e63dce1fbec118fb5252c7b04cbcd4

Can we download an attachment by querying just with the filename?

I tried: https://servicenow-instance.ourdomain.com/sys_attachment.do?file_name=myfile.xls but it didn't work.

Thanks in advance.

 

15 REPLIES 15

Then sorry. There's not such URL.

Attachment meta data is saved in sys_attachment table but the actually attachment file is saved in sys_attachment_doc table and the file may be broken into several records in the table. The only way to download the file in one piece is to use the API.

If it is necessary to download the file without using the API, use web page automation tool.

I'm not sure if the new ServiceNow RPA will be able to do this.

https://www.servicenow.com/workflows/creator-workflows/what-is-robotic-process-automation.html

Then sorry. There's not such URL.

Attachment meta data is saved in sys_attachment table but the actually attachment file is saved in sys_attachment_doc table but the files may be broken into several records. The only way to download the file in one piece is to use the API.

If it is necessary to download the file without using the API, use web page automation tool.

I'm not sure if the new ServiceNow RPA will be able to do this.

https://www.servicenow.com/workflows/creator-workflows/what-is-robotic-process-automation.html

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Ovin,

It's probably sys_id because filename is not unique.

It's possible to attach a file with the same name is different records. It's even possible to attach a file with the same name on the same form.

example. In the following form, 2 attachments with the same filename are attached.

find_real_file.png

Hi Hitoshi,

Thanks for pointing that out. I am not very well versed with ServiceNow but in our case, we navigate to a URL like: https://servicenow-instance.ourdomain.com?id=kb_article_view_1&sysparm_article=KB0803265&sys_kb_id=076e5c431c474998ea49ce49a04bae51&spa=1

which contains several hyperlinks and the hyperlink to the file we use (i.e. myfile.xls) points to the link mentioned above (https://servicenow-instance.ourdomain.com/sys_attachment.do?sys_id=21e63dce1fbec118fb5252c7b04cbcd4)

Is there a way we can fetch the latest version of the excel file by mentioning its name in the URL instead of the sys_id?

 

Thanks,

Ovin

It's possible by specifying the sys_kb_id and the filename if the filename is unique in the kb article.

As I've replied earlier, it's possible to attach files with different contents but with the same name to an article.

>latest version of the excel file

It'll be difficult to know the "latest" version but possible to find the "last" file that was uploaded.