GlideSysAttachment - Scoped
-
- UpdatedJan 30, 2025
- 4 minutes to read
- Yokohama
- API reference
The GlideSysAttachment API provides methods to handle attachments.
Content is returned as a string, not as a byte array when getContent() is called.
Content is returned as a GlideScriptableInputStream object when getContentStream() is called. The GlideScriptableInputStream contains the actual bytes not converted into a string.
Scoped GlideSysAttachment - GlideSysAttachment()
Creates an instance of the GlideSysAttachment class.
Name | Type | Description |
---|---|---|
None |
Scoped GlideSysAttachment - copy(String sourceTable, String sourceID, String targetTable, String targetID)
Copies attachments from the source record to the target record.
Type | Description |
---|---|
String | Array of sys_ids of the attachments that were copied. |
Example
Output:
Scoped GlideSysAttachment - deleteAttachment(String attachmentID)
Deletes the specified attachment.
Name | Type | Description |
---|---|---|
attachmentID | String | Attachment's sys_id. |
Type | Description |
---|---|
void |
Example
Scoped GlideSysAttachment - getAttachments(String tableName, String sys_id)
Returns a GlideRecord containing the matching attachment metadata such as name, type, or size.
Name | Type | Description |
---|---|---|
tableName | String | Name of the table to which the attachment belongs; for example, incident. |
sys_id | String | Sys_id of record to which the attachment belongs. |
Type | Description |
---|---|
GlideRecord | GlideRecord object containing the matching attachment metadata such as name, type, or size. |
Example
The following script lists attachment file names for a record with two attachments.
Output:
Scoped GlideSysAttachment - getContent(GlideRecord sysAttachment)
Returns the attachment content as a string.
This method is for use in scoped applications only. This method returns undefined
when used in the global scope. To read attachment content in the global scope, use the getContentStream()
method from the GlideSysAttachment - Global API.
- CSV (*.csv)
- JSON (*.json)
- Text (*.txt)
Name | Type | Description |
---|---|---|
sysAttachment | GlideRecord | Attachment record. |
Type | Description |
---|---|
String | Attachment contents as a string. Returns up to 5MB of data. |
Example
Output:
Scoped GlideSysAttachment - getContentBase64(GlideRecord sysAttachment)
Returns the attachment content as a string with base64 encoding.
This method is for use in scoped applications only. This method returns
undefined
when used in the global scope. To read attachment content in
the global scope, use the getContentStream method from the
GlideSysAttachment - Global API.
Name | Type | Description |
---|---|---|
sysAttachment | GlideRecord | Attachment record. |
Type | Description |
---|---|
String | Attachment contents as a string with base64 encoding. Returns up to 5MB of data. |
Example
Output:
Scoped GlideSysAttachment - getContentStream(String sysID)
Returns a GlideScriptableInputStream object given the sys_id of an attachment.
You can use the GlideTextReader API to read the content stream.
Name | Type | Description |
---|---|---|
sysID | String | Attachment sys_id. |
Type | Description |
---|---|
GlideScriptableInputStream | Stream that contains the attachment content. |
Example
Output:
Scoped GlideSysAttachment - write(GlideRecord record, String fileName, String contentType, String content)
Attaches a specified attachment to the specified record.
Type | Description |
---|---|
String | Attachment sys_id. Returns null if the attachment was not added. |
Example
Output:
Scoped GlideSysAttachment - writeBase64(GlideRecord now_GR, String fileName, String contentType, String content_base64Encoded)
Inserts an attachment for the specified record using base64 encoded content.
Type | Description |
---|---|
String | Sys_id of the attachment created. |
Example
Output:
Scoped GlideSysAttachment - writeContentStream(GlideRecord now_GR, String fileName, String contentType, GlideScriptableInputStream inputStream)
Inserts an attachment using the input stream.
Type | Description |
---|---|
String | Sys_id of the attachment created. |
Example
Attaches a content stream from the sys_attachment table to a test_table record.
On this page
- Scoped GlideSysAttachment - GlideSysAttachment()
- Scoped GlideSysAttachment - copy(String sourceTable, String sourceID, String targetTable, String targetID)
- Scoped GlideSysAttachment - deleteAttachment(String attachmentID)
- Scoped GlideSysAttachment - getAttachments(String tableName, String sys_id)
- Scoped GlideSysAttachment - getContent(GlideRecord sysAttachment)
- Scoped GlideSysAttachment - getContentBase64(GlideRecord sysAttachment)
- Scoped GlideSysAttachment - getContentStream(String sysID)
- Scoped GlideSysAttachment - write(GlideRecord record, String fileName, String contentType, String content)
- Scoped GlideSysAttachment - writeBase64(GlideRecord now_GR, String fileName, String contentType, String content_base64Encoded)
- Scoped GlideSysAttachment - writeContentStream(GlideRecord now_GR, String fileName, String contentType, GlideScriptableInputStream inputStream)