Trying to get sys id from Attachemnt

Jonas VK
Tera Guru

Hi, i am having an issue with my script include. in my script include I am creating a csv file to save to the "sys_attachment" table. to do this I have created this code

// create file and save
		var grRec = new GlideRecord("sys_attachment");
		grRec.addQuery('table_sys_id',current.sys_id);
		grRec.initialize();
		var grAttachment = new GlideSysAttachment();
		attachmentId = grAttachment.write(grRec, fileName, 'application/csv',csvContent);

 

my issue is, how can i get the sys_id or the "table_sys_id" from my attachment in the script?since i am making a link to the attachment to download it. 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

write() method requires 1st parameter as the GlideRecord object of the record where you wish to attach the file.

Example: you can query incident table with some incident number and pass the object as 1st parameter

check the docs

GlideSysAttachment

Your attachmentId variable will hold the sysId of the sys_attachment record

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

write() method requires 1st parameter as the GlideRecord object of the record where you wish to attach the file.

Example: you can query incident table with some incident number and pass the object as 1st parameter

check the docs

GlideSysAttachment

Your attachmentId variable will hold the sysId of the sys_attachment record

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader