Development · LessonBy Praveen T, ServiceNow Trainer, 9 yrs · Published · ServiceNow · all levels
Attachments and the Attachment API
Read, write, copy and validate attachments from script and from integrations.
Quick answer
Read, write, copy and validate attachments from script and from integrations.
Key takeaways
- Use GlideSysAttachment or the REST API, never the raw tables
- copy is the supported way to move files between records
- Validate type and size on anything user supplied
- Attachments consume storage, include them in retention plans
How attachments are stored
Attachment metadata lives in sys_attachment with the content chunked in sys_attachment_doc. Never touch those tables directly, use GlideSysAttachment or the Attachment API so chunking, size limits and permissions are handled.
Script examples
The common operations are copy, write and read.
var gsa = new GlideSysAttachment();
// copy every attachment from one record to another
gsa.copy('incident', sourceId, 'problem', targetId);
// write a generated file
var id = gsa.write(gr, 'summary.txt', 'text/plain', body);
// read text content
var text = gsa.getContent(attachmentGr);Inbound from integrations
The REST Attachment API accepts binary uploads against a table and sys_id.
- Validate the content type, do not trust the extension
- Set a maximum size property and enforce it in the flow or script
- Scan or restrict types where users upload to public facing forms
- Attachments count toward instance storage, archive old records
Practice challenge
+0 XPStreak ×0
Question 1 of 2
Which class handles attachment operations in script?
Frequently asked questions
How large can an attachment be?
The limit is controlled by a property and defaults to a conservative value. Raise it deliberately and consider the effect on storage and mail.
Can a flow add an attachment?
Yes, attachment actions exist in Flow Designer, and a script step can call GlideSysAttachment when you need more control.