Getting Record Attachments via API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 01:53 AM
Hi all,
Is there a way to get all attachments sys_ids for a specific record via API?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 01:58 AM - edited 04-11-2024 02:03 AM
Hi @AleksaStojanov ,
Attachments are stored in sys_attachment table . so if you want to get all the attachment sys_id for particaular record please use below script -
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id',current.sys_id); // current record sys_id
attachment.query();
while(attachment.next()){
gs.info('sys_id of the attachment is : ' +attachment.sys_id);
}
if my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
Thanks,
Astik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 10:32 AM
Is it possible to do this with the REST API instead of through a ServiceNOW script?
I'm writing a python script that interacts with the ServiceNOW API and the goal of the script is to pull the attachments associated to a list of ServiceNow records. I'm stuck on trying to find the relationship between a given record and it's attachments.
I see our 'sys_attachment' table has fields 'table_name' and 'u_record' where:
- 'table_name': is the name of the table of the record the attachment is from
- 'u_record' is a 'Document ID' field that is a reference to a given record
I've been trying to supply the sys_id of the record I want to get the attachments of as the 'u_record' parameter but I haven't had luck. These were being supplied to the 'Get Table' endpoint as well as the 'Get Attachment Metadata' endpoint.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:24 AM
Hi @lmahoney,
It is posible, I used this approach
<instance_url>/api/now/table/sys_attachment?sysparm_query=table_sys_id=<record_id>