---
sourceDocument: Australia API Reference
sourceDocumentLink: https://www.servicenow.com/docs/r/api-reference

 Release :

    - australia

ft:locale :

    - en-US

ft:publication_title :

    - Australia API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideSysAttachment - Global

# GlideSysAttachment - Global {#ariaid-title1}

* Release version: Australia
* 
* Updated March 12, 2026
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 10 minutes to read

The GlideSysAttachment API provides methods for handling attachments.

Content is returned as a GlideScriptableInputStream object when getContentStream() is called. The GlideScriptableInputStream contains the actual bytes not converted into a string.

## Encryption API scope restriction {#GlideSysAttachmentGlobalAPI__encryption-restrictions}

Methods that manage encryption contexts, cryptographic modules, or encryption state are available only in the global application. These APIs are intentionally restricted because they modify platform‑level security
configuration.

## GlideSysAttachment -
GlideSysAttachment() {#ariaid-title2}

Creates an instance of the GlideSysAttachment class.
Note:  
This constructor does not take a parameter unless managing attachment attributes.  
Use the following methods for managing attachment attributes:

* [addAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addAttribute_S_S "Adds a single attribute to an existing attachment record.")
* [addMultipleAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addMultipleAttributes_O "Adds multiple attributes to an attachment record.")
* [deleteAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAllAttributes "Deletes all attributes from an existing attachment record.")
* [deleteAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAttribute_S "Deletes a specified attribute from attachment record.")
* [fetchAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAllAttributes "Fetches all attributes from a specified attachment record.")
* [fetchAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAttribute "Fetches a specified attribute from an attachment record.")
* [updateAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAllAttributes_O "Updates all the attributes for an existing attachment record.")
* [updateAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAttribute_S_S "Updates a single attribute for an existing attachment record.")
{#GSA-GlideSysAttachment__ul_uwj_4yq_zfc}
{#GSA-GlideSysAttachment__table_iys_ctb_fv__entry__3}

| Name | Type | Description |
|-|-|-|
| idAttachmentAttributes | String | This parameter is only used when handling attachment attributes, otherwise leave empty. Sys_id of an attachment with attributes. Table: Attachments \[sys_attachment\] |
[Table 1. Parameters]

{#GSA-GlideSysAttachment__table_iys_ctb_fv}  
The following script lists attachment file names for a record with two attachments.

    var attachment = new GlideSysAttachment();

    var agr = attachment.getAttachments('<table_name>', '<record_sys_id>');

    while(agr.next())
    gs.info(agr.getValue('file_name'));

Output:

    *** Script: filename1.txt
    *** Script: filename2.txt

The following example shows how to get all attributes assigned to a specified attachment.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var result = attach.fetchAllAttributes();

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value')); 
    }

Output:

    Key: title, Value: Add multiple attributes to an attachment
    Key: author, Value: Abel Tuter
    Key: category, Value: KB
    Key: length, Value: 5000

## GlideSysAttachment - addAttribute(String attrKey, String attrValue) {#ariaid-title3}

Adds a single attribute to an existing attachment record.
See also:

* [addMultipleAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addMultipleAttributes_O "Adds multiple attributes to an attachment record.")
* [deleteAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAllAttributes "Deletes all attributes from an existing attachment record.")
* [deleteAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAttribute_S "Deletes a specified attribute from attachment record.")
* [fetchAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAllAttributes "Fetches all attributes from a specified attachment record.")
* [fetchAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAttribute "Fetches a specified attribute from an attachment record.")
* [updateAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAllAttributes_O "Updates all the attributes for an existing attachment record.")
* [updateAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAttribute_S_S "Updates a single attribute for an existing attachment record.")

{#GSA-addAttribute_S_S__ul_uwj_4yq_zfc}For the scoped equivalent of this method, use [Scoped GlideSysAttachment - addAttribute(String sysAttachmentID, String attrKey, String attrValue)](https://www.servicenow.com/docs/HBoKF45_FRddbuZ7MXGYQA#SGSA-addAttribute_S_S_S "Adds a single attribute to an existing attachment record.").
{#GSA-addAttribute_S_S__table_rql_3mg_5fc__entry__3}

| Name | Type | Description |
|-|-|-|
| attrKey | String | Key portion of a key-value pair for an attachment attribute. |
| attrValue | String | Value portion of a key-value pair for an attachment attribute. |
[Table 2. Parameters]

{#GSA-addAttribute_S_S__table_rql_3mg_5fc} {#GSA-addAttribute_S_S__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 3. Returns]

{#GSA-addAttribute_S_S__table_sql_3mg_5fc}  
The following example shows how to add an attribute to a specified attachment with the key <kbd class="ph userinput">author</kbd> and value <kbd class="ph userinput">Fred Luddy</kbd>. The results can be viewed
in the Attachment Attributes \[sys_attachment_attribute\] table.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");
    attach.addAttribute("author", "Fred Luddy");

    var result = attach.fetchAttribute("author");

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + " \nValue: " + result.getValue('value')); 
    }

Output:

    Key: author 
    Value: Fred Luddy

## GlideSysAttachment - addMultipleAttributes(Object attrsKeyValuePair) {#ariaid-title4}

Adds multiple attributes to an attachment record.
See also:

* [addAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addAttribute_S_S "Adds a single attribute to an existing attachment record.")
* [deleteAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAllAttributes "Deletes all attributes from an existing attachment record.")
* [deleteAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAttribute_S "Deletes a specified attribute from attachment record.")
* [fetchAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAllAttributes "Fetches all attributes from a specified attachment record.")
* [fetchAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAttribute "Fetches a specified attribute from an attachment record.")
* [updateAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAllAttributes_O "Updates all the attributes for an existing attachment record.")
* [updateAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAttribute_S_S "Updates a single attribute for an existing attachment record.")

{#GSA-addMultipleAttributes_O__ul_uwj_4yq_zfc}For the scoped equivalent of this method, use [Scoped GlideSysAttachment - addMultipleAttributes(String sysAttachmentID, Object attrsKeyValuePair)](https://www.servicenow.com/docs/HBoKF45_FRddbuZ7MXGYQA#SGSA-addMultipleAttributes_S_O "Adds multiple attributes to an attachment record.").
{#GSA-addMultipleAttributes_O__table_rql_3mg_5fc__entry__3}

| Name | Type | Description |
|-|-|-|
| attrsKeyValuePair | Object | Attachment attributes in a set of key-value pairs. Each attribute key and its value must be provided as a string. For example: var attachmentAttributes = { "description" : "Photo of the solar system", "dimensions" : "1600 x 300" } |
[Table 4. Parameters]

{#GSA-addMultipleAttributes_O__table_rql_3mg_5fc} {#GSA-addMultipleAttributes_O__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 5. Returns]

{#GSA-addMultipleAttributes_O__table_sql_3mg_5fc}  
The following example shows how to add attributes to a specified attachment. The results can also be verified in the Attachment Attributes \[sys_attachment_attribute\] table.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var attrsKeyValuePair = { };
      attrsKeyValuePair["title"]  = "Add multiple attributes to an attachment";
      attrsKeyValuePair["category"] =  "KB";
      attrsKeyValuePair["length"] =  "5000";

    attach.addMultipleAttributes(attrsKeyValuePair);

    var result = attach.fetchAllAttributes();

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value'));
    }

Output:

    Key: title, Value: Add multiple attributes to an attachment
    Key: author, Value: Abel Tuter
    Key: category, Value: KB
    Key: length, Value: 5000

## GlideSysAttachment - copy(String sourceTable, String sourceID, String targetTable, String targetID) {#ariaid-title5}

Copies attachments from the source record to the target record.
Note:  
Copying an attachment also copies any attributes assigned to it. You can view a list of assigned attributes in the Attachment Attributes \[sys_attachment_list\] table, or run the fetchAllAttributes() method.
{#GSA-copy_S_S_S_S__id_g4d_yjz_g5b__entry__3}

| Name | Type | Description |
|-|-|-|
| sourceTable | String | Name of the table with the attachments to be copied. |
| sourceID | String | Source table's sys_id. |
| targetTable | String | Name of the table on which to add the attachments. |
| targetID | String | The sys_id of the record in the target table on which to copy the attachment. |
[Table 6. Parameters]

{#GSA-copy_S_S_S_S__id_g4d_yjz_g5b} {#GSA-copy_S_S_S_S__id_afm_yjz_g5b__entry__2}

| Type | Description |
|-|-|
| String | Array of sys_ids of the attachments that were copied. Table: Attachments \[sys_attachment\] |
[Table 7. Returns]

{#GSA-copy_S_S_S_S__id_afm_yjz_g5b}  
This example shows how to copy attachments from an incident record to a problem record.

    var attachment = new GlideSysAttachment();
    var incidentSysID = 'ab1b30031b04ec101363ff37dc4bcbfc';
    var incGR = new GlideRecord('incident');
    incGR.get(incidentSysID);

    var copiedAttachments = attachment.copy('incident', incidentSysID, 'problem', incGR.getValue('problem_id'));
    gs.info('Copied attachments: ' + copiedAttachments);

Output:

    Copied attachments: 6e4621df1bc420501363ff37dc4bcbb0,a87769531b0820501363ff37dc4bcba2

## GlideSysAttachment - deleteAllAttributes() {#ariaid-title6}

Deletes all attributes from an existing attachment record.
See also:

* [addAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addAttribute_S_S "Adds a single attribute to an existing attachment record.")
* [addMultipleAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addMultipleAttributes_O "Adds multiple attributes to an attachment record.")
* [deleteAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAttribute_S "Deletes a specified attribute from attachment record.")
* [fetchAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAllAttributes "Fetches all attributes from a specified attachment record.")
* [fetchAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAttribute "Fetches a specified attribute from an attachment record.")
* [updateAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAllAttributes_O "Updates all the attributes for an existing attachment record.")
* [updateAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAttribute_S_S "Updates a single attribute for an existing attachment record.")

{#GSA-deleteAllAttributes__ul_uwj_4yq_zfc}For the scoped equivalent of this method, use [Scoped GlideSysAttachment - deleteAllAttributes(String sysAttachmentID)](https://www.servicenow.com/docs/HBoKF45_FRddbuZ7MXGYQA#SGSA-deleteAllAttributes_S "Deletes all attributes from an existing attachment record.").
{#GSA-deleteAllAttributes__table_rql_3mg_5fc__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 8. Parameters]

{#GSA-deleteAllAttributes__table_rql_3mg_5fc} {#GSA-deleteAllAttributes__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the attributes were successfully deleted. Valid values: * true: The attributes were successfully deleted. * false: The attributes were not successfully deleted. {#GSA-deleteAllAttributes__ul_kwy_cth_5fc} |
[Table 9. Returns]

{#GSA-deleteAllAttributes__table_sql_3mg_5fc}  
The following example shows how to delete all attributes assigned to a specified attachment. The results can also be verified in the Attachment Attributes \[sys_attachment_attribute\] table.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    attach.deleteAllAttributes();

    var result = attach.fetchAllAttributes();

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value')); 
    }

Output:

    Attribute "null" not found for attachment "04f48541083e2e50f877df7a115e31f3"

## GlideSysAttachment - deleteAttachment(String attachmentID) {#ariaid-title7}

Deletes the specified attachment.
Note:  
Deleting an attachment also deletes any attributes assigned to it. You can view a list of assigned attributes in the Attachment Attributes \[sys_attachment\] table, or run the fetchAllAttributes() method.
{#GSA-deleteAttachment_S__id_ywb_ykz_g5b__entry__3}

| Name | Type | Description |
|-|-|-|
| attachmentID | String | Attachment's sys_id. Table: Attachments \[sys_attachment\] |
[Table 10. Parameters]

{#GSA-deleteAttachment_S__id_ywb_ykz_g5b} {#GSA-deleteAttachment_S__table_gjy_lyb_fv__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 11. Returns]

{#GSA-deleteAttachment_S__table_gjy_lyb_fv}  

    var attachment = new GlideSysAttachment();
    var attachmentSysID = 'a87769531b0820501363ff37dc4bcba2';
    attachment.deleteAttachment(attachmentSysID);

## GlideSysAttachment - deleteAttribute(String attrKey) {#ariaid-title8}

Deletes a specified attribute from attachment record.
See also:

* [addAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addAttribute_S_S "Adds a single attribute to an existing attachment record.")
* [addMultipleAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addMultipleAttributes_O "Adds multiple attributes to an attachment record.")
* [deleteAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAllAttributes "Deletes all attributes from an existing attachment record.")
* [fetchAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAllAttributes "Fetches all attributes from a specified attachment record.")
* [fetchAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAttribute "Fetches a specified attribute from an attachment record.")
* [updateAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAllAttributes_O "Updates all the attributes for an existing attachment record.")
* [updateAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAttribute_S_S "Updates a single attribute for an existing attachment record.")

{#GSA-deleteAttribute_S__ul_uwj_4yq_zfc}For the scoped equivalent of this method, use [Scoped GlideSysAttachment - deleteAllAttributes(String sysAttachmentID)](https://www.servicenow.com/docs/HBoKF45_FRddbuZ7MXGYQA#SGSA-deleteAllAttributes_S "Deletes all attributes from an existing attachment record.").
{#GSA-deleteAttribute_S__table_rql_3mg_5fc__entry__3}

| Name | Type | Description |
|-|-|-|
| attrKey | String | Key portion of a key-value pair for an attachment attribute. |
[Table 12. Parameters]

{#GSA-deleteAttribute_S__table_rql_3mg_5fc} {#GSA-deleteAttribute_S__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the attachment attribute was successfully deleted. Valid values: * true: The attachment attribute was successfully deleted. * false: The attachment attribute was not successfully deleted. {#GSA-deleteAttribute_S__ul_val_cth_5fc} |
[Table 13. Returns]

{#GSA-deleteAttribute_S__table_sql_3mg_5fc}  
The following example shows how to delete an attribute assigned to a specified attachment with the key <kbd class="ph userinput">author</kbd>. The results can also be verified in the Attachment
Attributes \[sys_attachment_attribute\] table.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3v");

    attach.deleteAttribute("author");

    var result = attach.fetchAttribute("author");

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + " \nValue: " + result.getValue('value')); 
    }

Output:

    Attribute "author" not found for attachment "04f48541083e2e50f877df7a115e31f3"

## GlideSysAttachment - fetchAllAttributes() {#ariaid-title9}

Fetches all attributes from a specified attachment record.
See also:

* [addAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addAttribute_S_S "Adds a single attribute to an existing attachment record.")
* [addMultipleAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addMultipleAttributes_O "Adds multiple attributes to an attachment record.")
* [deleteAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAllAttributes "Deletes all attributes from an existing attachment record.")
* [deleteAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAttribute_S "Deletes a specified attribute from attachment record.")
* [fetchAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAttribute "Fetches a specified attribute from an attachment record.")
* [updateAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAllAttributes_O "Updates all the attributes for an existing attachment record.")
* [updateAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAttribute_S_S "Updates a single attribute for an existing attachment record.")

{#GSA-fetchAllAttributes__ul_uwj_4yq_zfc}For the scoped equivalent of this method, use [Scoped GlideSysAttachment - fetchAllAttributes(String sysAttachmentID)](https://www.servicenow.com/docs/HBoKF45_FRddbuZ7MXGYQA#SGSA-fetchAllAttributes_S "Fetches all attributes from a specified attachment record.").
{#GSA-fetchAllAttributes__table_rql_3mg_5fc__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 14. Parameters]

{#GSA-fetchAllAttributes__table_rql_3mg_5fc} {#GSA-fetchAllAttributes__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| [GlideRecord](https://www.servicenow.com/docs/A8srNukp_c6TJp_LS_KZMg#c_GlideRecordScopedAPI "The scoped GlideRecord API is used for database operations.") | The attachment record and all of its attributes. |
[Table 15. Returns]

{#GSA-fetchAllAttributes__table_sql_3mg_5fc}  
The following example shows how to get all attributes assigned to a specified attachment.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var result = attach.fetchAllAttributes();

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value')); 
    }

Output:

    Key: title, Value: Add multiple attributes to an attachment
    Key: author, Value: Abel Tuter
    Key: category, Value: KB
    Key: length, Value: 5000

## GlideSysAttachment - fetchAttribute(String attrKey) {#ariaid-title10}

Fetches a specified attribute from an attachment record.
See also:

* [addAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addAttribute_S_S "Adds a single attribute to an existing attachment record.")
* [addMultipleAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addMultipleAttributes_O "Adds multiple attributes to an attachment record.")
* [deleteAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAllAttributes "Deletes all attributes from an existing attachment record.")
* [deleteAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAttribute_S "Deletes a specified attribute from attachment record.")
* [fetchAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAllAttributes "Fetches all attributes from a specified attachment record.")
* [updateAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAllAttributes_O "Updates all the attributes for an existing attachment record.")
* [updateAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAttribute_S_S "Updates a single attribute for an existing attachment record.")

{#GSA-fetchAttribute__ul_uwj_4yq_zfc}For the scoped equivalent of this method, use [Scoped GlideSysAttachment - fetchAttribute(String sysAttachmentID, String attrKey)](https://www.servicenow.com/docs/HBoKF45_FRddbuZ7MXGYQA#SGSA-fetchAttribute_S_S "Fetches a specified attribute from an attachment record.").
{#GSA-fetchAttribute__table_rql_3mg_5fc__entry__3}

| Name | Type | Description |
|-|-|-|
| attrKey | String | Key portion of a key-value pair for an attachment attribute. |
[Table 16. Parameters]

{#GSA-fetchAttribute__table_rql_3mg_5fc} {#GSA-fetchAttribute__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| [GlideRecord](https://www.servicenow.com/docs/A8srNukp_c6TJp_LS_KZMg#c_GlideRecordScopedAPI "The scoped GlideRecord API is used for database operations.") | The GlideRecord of the attachment and the specified attribute. |
[Table 17. Returns]

{#GSA-fetchAttribute__table_sql_3mg_5fc}  
The following example shows how to get an attachment attribute with the key <kbd class="ph userinput">author</kbd>.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var result = attach.fetchAttribute("author");

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + " \nValue: " + result.getValue('value')); 
    }

Output:

    Key: author 
    Value: Abel Tuter

## GlideSysAttachment - getAttachments(String tableName, String sys_id) {#ariaid-title11}

Returns a GlideRecord containing the matching attachment metadata such as name, type,
or size.
{#GSA-getAttachments_S_S__id_m5v_14z_g5b__entry__3}

| 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. |
[Table 18. Parameters]

{#GSA-getAttachments_S_S__id_m5v_14z_g5b} {#GSA-getAttachments_S_S__id_qr3_c4z_g5b__entry__2}

| Type | Description |
|-|-|
| GlideRecord | GlideRecord object containing the matching attachment metadata such as name, type, or size. |
[Table 19. Returns]

{#GSA-getAttachments_S_S__id_qr3_c4z_g5b}  
The following script lists attachment file names for a record with two attachments.

    var attachment = new GlideSysAttachment();

    var agr = attachment.getAttachments('<table_name>', '<record_sys_id>');

    while(agr.next())
    gs.info(agr.getValue('file_name'));

Output:

    *** Script: filename1.txt
    *** Script: filename2.txt

## GlideSysAttachment - getContentStream(String sysID) {#ariaid-title12}

Returns a GlideScriptableInputStream object given the sys_id of an
attachment.
You can use the [GlideTextReader](https://www.servicenow.com/docs/9gnaixkHczN0SE0IXlBuLg#c_GlideTextReaderScopedAPI "The GlideTextReader API provides the ability to read single lines from an input stream. Because an input stream is used, it is not subject to the 5MB attachment size limit.") API to read the content stream.
{#GSA-getContentStream_S__id_sdc_44z_g5b__entry__3}

| Name | Type | Description |
|-|-|-|
| sysID | String | Attachment sys_id. |
[Table 20. Parameters]

{#GSA-getContentStream_S__id_sdc_44z_g5b} {#GSA-getContentStream_S__id_nqx_44z_g5b__entry__2}

| Type | Description |
|-|-|
| GlideScriptableInputStream | Stream that contains the attachment content. |
[Table 21. Returns]

{#GSA-getContentStream_S__id_nqx_44z_g5b}  

    var attachment = new GlideSysAttachment();
    var attachmentSysID = '6e4621df1bc420501363ff37dc4bcbb0';
    var attachmentContentStream = attachment.getContentStream(attachmentSysID);
    gs.info('Attachment content stream: ' + attachmentContentStream);

Output:

    Attachment content stream: com.glide.communications.GlideScriptableInputStream@14bd299

## GlideSysAttachment - updateAllAttributes(Object attrsKeyValuePair) {#ariaid-title13}

Updates all the attributes for an existing attachment record.
See also:

* [addAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addAttribute_S_S "Adds a single attribute to an existing attachment record.")
* [addMultipleAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addMultipleAttributes_O "Adds multiple attributes to an attachment record.")
* [deleteAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAllAttributes "Deletes all attributes from an existing attachment record.")
* [deleteAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAttribute_S "Deletes a specified attribute from attachment record.")
* [fetchAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAllAttributes "Fetches all attributes from a specified attachment record.")
* [fetchAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAttribute "Fetches a specified attribute from an attachment record.")
* [updateAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAttribute_S_S "Updates a single attribute for an existing attachment record.")

{#GSA-updateAllAttributes_O__ul_uwj_4yq_zfc}For the scoped equivalent of this method, use [Scoped GlideSysAttachment - updateAllAttributes(String sysAttachmentID, Object attrsKeyValuePair)](https://www.servicenow.com/docs/HBoKF45_FRddbuZ7MXGYQA#SGSA-updateAllAttributes_S_O "Updates all the attributes for an existing attachment record.").
{#GSA-updateAllAttributes_O__table_rql_3mg_5fc__entry__3}

| Name | Type | Description |
|-|-|-|
| attrsKeyValuePair | Object | Attachment attributes in a set of key-value pairs. Each attribute key and its value must be provided as a string. For example: var attachmentAttributes = { "description" : "Photo of the solar system", "dimensions" : "1600 x 300" } |
[Table 22. Parameters]

{#GSA-updateAllAttributes_O__table_rql_3mg_5fc} {#GSA-updateAllAttributes_O__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 23. Returns]

{#GSA-updateAllAttributes_O__table_sql_3mg_5fc}  
The following example shows how to update each attribute for a specified attachment. The results can also be verified in the Attachment Attributes \[sys_attachment_attribute\] table.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var attachmentAttributes = {
        "category" : "Training",
        "title" : "Updating attachment attributes", 
        "author" : "Abraham Lincoln",
        "length" : "6000"
    }

    attach.updateAllAttributes(attachmentAttributes);

    var result = attach.fetchAllAttributes();

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value'));
    }

Output:

    Key: title, Value: Updating attachment attributes
    Key: author, Value: Abraham Lincoln
    Key: category, Value: Training
    Key: length, Value: 6000

## GlideSysAttachment - updateAttribute(String attrKey, String attrValue) {#ariaid-title14}

Updates a single attribute for an existing attachment record.
See also:

* [addAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addAttribute_S_S "Adds a single attribute to an existing attachment record.")
* [addMultipleAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-addMultipleAttributes_O "Adds multiple attributes to an attachment record.")
* [deleteAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAllAttributes "Deletes all attributes from an existing attachment record.")
* [deleteAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-deleteAttribute_S "Deletes a specified attribute from attachment record.")
* [fetchAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAllAttributes "Fetches all attributes from a specified attachment record.")
* [fetchAttribute()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-fetchAttribute "Fetches a specified attribute from an attachment record.")
* [updateAllAttributes()](https://www.servicenow.com/docs/Pmi5thUhwEdQG~h8rRJqAA#GSA-updateAllAttributes_O "Updates all the attributes for an existing attachment record.")

{#GSA-updateAttribute_S_S__ul_uwj_4yq_zfc}For the scoped equivalent of this method, use [Scoped GlideSysAttachment - updateAttribute(String sysAttachmentID, String attrKey, String attrValue)](https://www.servicenow.com/docs/HBoKF45_FRddbuZ7MXGYQA#SGSA-updateAttribute_S_S_S "Updates a single attribute for an existing attachment record.").
{#GSA-updateAttribute_S_S__table_rql_3mg_5fc__entry__3}

| Name | Type | Description |
|-|-|-|
| attrKey | String | Key portion of a key-value pair for an attachment attribute. |
| attrValue | String | Value portion of a key-value pair for an attachment attribute. |
[Table 24. Parameters]

{#GSA-updateAttribute_S_S__table_rql_3mg_5fc} {#GSA-updateAttribute_S_S__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 25. Returns]

{#GSA-updateAttribute_S_S__table_sql_3mg_5fc}  
The following example shows how to update an attribute assigned to a specified attachment with the key <kbd class="ph userinput">author</kbd> and changes the value to Abel Tuter. The results can also be
verified in the Attachment Attributes \[sys_attachment_attribute\] table.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var originalVal = attach.fetchAttribute("author");
    while(originalVal.next()) {
       gs.info("Original attribute value: " + originalVal.getValue('value') + "\n"); 
    }

    attach.updateAttribute("author", "Abel Tuter");

    var updatedVal = attach.fetchAttribute("author"); 
    while(updatedVal.next()) {
       gs.info("Updated attribute value: " + updatedVal.getValue('value')); 
    }

Output:

    Original attribute value: Fred Luddy

    Updated attribute value: Abel Tuter

## GlideSysAttachment - write(GlideRecord record, String fileName, String contentType, String content) {#ariaid-title15}

Attaches a specified attachment to the specified record.
{#GSA-write_GR_S_S_S__id_odn_1pz_g5b__entry__3}

| Name | Type | Description |
|-|-|-|
| record | GlideRecord | Record to which to attach the attachment. |
| fileName | String | Attachment file name. |
| contentType | String | MIME type of the attachment, such as `image/png`. Located in the Attachment \[sys_attachment\] table in the Content type field. |
| content | String | Attachment content. |
[Table 26. Parameters]

{#GSA-write_GR_S_S_S__id_odn_1pz_g5b} {#GSA-write_GR_S_S_S__id_kbx_1pz_g5b__entry__2}

| Type | Description |
|-|-|
| String | Attachment sys_id. Returns null if the attachment was not added. |
[Table 27. Returns]

{#GSA-write_GR_S_S_S__id_kbx_1pz_g5b}  

    var attachment = new GlideSysAttachment();

    //set up inputs
    var rec = new GlideRecord('incident');
    rec.get('78271e1347c12200e0ef563dbb9a7109');
    var fileName = 'example.txt';
    var contentType = 'text/csv';
    var content = 'The text that is stored inside my file';

    var agr = attachment.write(rec, fileName, contentType, content);

    gs.info('The attachment sys_id is: ' + agr);

Output:

    The attachment sys_id is: 01271e4317c13311e0ef563dbb9abe34

## GlideSysAttachment - writeContentStream(GlideRecord now_GR, String fileName, String contentType, GlideScriptableInputStream inputStream) {#ariaid-title16}

Inserts an attachment using the input stream.
{#GSA-writeContentStrm_GR_S_S_GSIS__id_trk_jpz_g5b__entry__3}

| Name | Type | Description |
|-|-|-|
| now_GR | GlideRecord | Record to which to attach the attachment. |
| fileName | String | Attachment file name. |
| contentType | String | MIME type of the attachment, such as `image/png`. Located in the Attachment \[sys_attachment\] table in the Content type field. |
| content | GlideScriptableInputStream | Attachment content. |
[Table 28. Parameters]

{#GSA-writeContentStrm_GR_S_S_GSIS__id_trk_jpz_g5b} {#GSA-writeContentStrm_GR_S_S_GSIS__id_ncv_jpz_g5b__entry__2}

| Type | Description |
|-|-|
| String | Sys_id of the attachment created. |
[Table 29. Returns]

{#GSA-writeContentStrm_GR_S_S_GSIS__id_ncv_jpz_g5b}  
Attaches a content stream from the sys_attachment table to a test_table record.

    function copyAttachmentToGlideRecord(conceptSysId) {

      // Get record from test_table using sys_id
      var targetGlideRecord = new GlideRecord("test_table");
      if (!targetGlideRecord.get(conceptSysId)) {
         throw ("Cannot find record created by test with sys_id: " + conceptSysId);
      }

      // Get record from sys_attachment table
      var sourceAttachmentGlideRecord = new GlideRecord('sys_attachment');    
      sourceAttachmentGlideRecord.query();
      sourceAttachmentGlideRecord.next();

      // Get field values from retrieved sys_attachment record
      var fileName = sourceAttachmentGlideRecord.getValue('file_name');
      var contentType = sourceAttachmentGlideRecord.getValue('content_type');
      var sourceAttachmentSysId = sourceAttachmentGlideRecord.getValue('sys_id');

      // Attach sys_attachment record content stream to test_table record
      var gsa = new GlideSysAttachment();
      gsa.writeContentStream(
        targetGlideRecord,
        fileName,
        contentType,
        gsa.getContentStream(sourceAttachmentSysId));
      gs.info("Attachment created");
    }


