Get all sys_ids of attachments for an incident

parvbionics
Kilo Contributor

Ho can i get all sys_ids of the attachments for a particular incident?

 

my goal is to write a script to download the attachments one by one using curl command

 

parvbionics_0-1683879854343.png

There are a lot of attachments assigned to one incident and I want to get all  the sys_ids(may be using a query) for the attachments

1 REPLY 1

Devender Kumar
Tera Guru
Tera Guru

Hi parvbionics,

Please check the below script.

Using this script you will be able to extract the sys ids of attachments from particular incident.

var sysid='sys_id of incident';
//var sysid=current.sys_id;
var arr=[];
var gAttach=new GlideRecord('sys_attachment');
gAttach.addQuery('table_sys_id',sysid);
gAttach.query();
while(gAttach.next())
{
arr.push(gAttach.getValue('sys_id'));
}
gs.log("Attachments sys ids '+arr);

You can refer the below link to get an idea how we can download the attachments using curl.

 

https://www.servicenow.com/community/developer-forum/get-contents-of-attachment-record-using-curl/m-... 

 

If my answer help you to resolve your issue then please don't forget to mark correct or helpful.

Regards,

Devender