- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 06:21 AM
Hi All,
While copying the attachment from one record to another record using attachment.copy , How to get file name of the attachment.
Thanks
Ra
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 07:22 AM
Hi @Raji9 ,
You can Configure a after insert business rule on sys_attachment table and using getContentStream() and writeContentStream() methods to create an attachment on the target record.
Please refer to the sample Script in the Article : https://www.servicenow.com/community/itsm-articles/copying-attachment-from-one-record-to-another-rec...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 07:18 AM
What do you need the name for? It's just a one-on-one copy, adding it to another record.
But the name of the attachment is in the 'file_name' field on the record.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 07:22 AM
Hi @Raji9 ,
You can Configure a after insert business rule on sys_attachment table and using getContentStream() and writeContentStream() methods to create an attachment on the target record.
Please refer to the sample Script in the Article : https://www.servicenow.com/community/itsm-articles/copying-attachment-from-one-record-to-another-rec...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 08:24 AM
Hi @Raji9 ,
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);
gr.query();
if(gr.next()){//use `while` if dealing with multiple attachments
if(gr.getValue('file_name').indexOf('xlsx') != -1 && gr.getValue('file_name').indexOf('myfile') != -1){//meaning if you find a file with xls extension
//do something
}
}
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 08:45 AM
Hi @Raji9 ,
You can refer below articles,
https://www.servicenow.com/community/itsm-forum/get-attachment-file-name/td-p/642891
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang