{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":816,"path":"api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md","title":"GlideSysAttachment - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideSysAttachment- Global\n\nThe GlideSysAttachment API provides methods for handling attachments.\n\nContent is returned as a GlideScriptableInputStream object when getContentStream\\(\\) is called. The GlideScriptableInputStream contains the actual bytes not converted into a string.\n\n## Encryption API scope restriction\n\nMethods 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.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## GlideSysAttachment - GlideSysAttachment\\(\\)\n\nCreates an instance of the GlideSysAttachment class.\n\n**Note:** This constructor does not take a parameter unless managing attachment attributes.\n\nUse the following methods for managing attachment attributes:\n\n-   [addAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n\n<table id=\"table_iys_ctb_fv\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nidAttachmentAttributes\n\n</td><td>\n\nString\n\n</td><td>\n\nThis parameter is only used when handling attachment attributes, otherwise leave empty. Sys\\_id of an attachment with attributes.Table: Attachments \\[sys\\_attachment\\]\n\n</td></tr></tbody>\n</table>The following script lists attachment file names for a record with two attachments.\n\n```\nvar attachment = new GlideSysAttachment();\n\nvar agr = attachment.getAttachments('<table_name>', '<record_sys_id>');\n\nwhile(agr.next())\ngs.info(agr.getValue('file_name'));\n```\n\nOutput:\n\n```\n*** Script: filename1.txt\n*** Script: filename2.txt\n```\n\nThe following example shows how to get all attributes assigned to a specified attachment.\n\n```\nvar attach = new GlideSysAttachment(\"04f48541083e2e50f877df7a115e31f3\");\n\nvar result = attach.fetchAllAttributes();\n\nwhile(result.next()) {\n   gs.info(\"Key: \" + result.getValue('key') + \", Value: \" + result.getValue('value')); \n}\n```\n\nOutput:\n\n```\nKey: title, Value: Add multiple attributes to an attachment\nKey: author, Value: Abel Tuter\nKey: category, Value: KB\nKey: length, Value: 5000\n```\n\n## GlideSysAttachment - addAttribute\\(String attrKey, String attrValue\\)\n\nAdds a single attribute to an existing attachment record.\n\nSee also:\n\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n\nFor the scoped equivalent of this method, use [Scoped GlideSysAttachment - addAttribute\\(String sysAttachmentID, String attrKey, String attrValue\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|attrKey|String|Key portion of a key-value pair for an attachment attribute.|\n|attrValue|String|Value portion of a key-value pair for an attachment attribute.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to add an attribute to a specified attachment with the key `author` and value `Fred Luddy`. The results can be viewed in the Attachment Attributes \\[sys\\_attachment\\_attribute\\] table.\n\n```\nvar attach = new GlideSysAttachment(\"04f48541083e2e50f877df7a115e31f3\");\nattach.addAttribute(\"author\", \"Fred Luddy\");\n\nvar result = attach.fetchAttribute(\"author\");\n\nwhile(result.next()) {\n   gs.info(\"Key: \" + result.getValue('key') + \" \\nValue: \" + result.getValue('value')); \n}\n```\n\nOutput:\n\n```\nKey: author \nValue: Fred Luddy\n```\n\n## GlideSysAttachment - addMultipleAttributes\\(Object attrsKeyValuePair\\)\n\nAdds multiple attributes to an attachment record.\n\nSee also:\n\n-   [addAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n\nFor the scoped equivalent of this method, use [Scoped GlideSysAttachment - addMultipleAttributes\\(String sysAttachmentID, Object attrsKeyValuePair\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md).\n\n<table id=\"table_rql_3mg_5fc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nattrsKeyValuePair\n\n</td><td>\n\nObject\n\n</td><td>\n\nAttachment attributes in a set of key-value pairs. Each attribute key and its value must be provided as a string.For example:\n\n```\nvar attachmentAttributes = { \n    \"description\" : \"Photo of the solar system\",\n    \"dimensions\" : \"1600 x 300\"\n}\n```\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThe 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.\n\n```\nvar attach = new GlideSysAttachment(\"04f48541083e2e50f877df7a115e31f3\");\n\nvar attrsKeyValuePair = { };\n  attrsKeyValuePair[\"title\"]  = \"Add multiple attributes to an attachment\";\n  attrsKeyValuePair[\"category\"] =  \"KB\";\n  attrsKeyValuePair[\"length\"] =  \"5000\";\n\nattach.addMultipleAttributes(attrsKeyValuePair);\n\nvar result = attach.fetchAllAttributes();\n\nwhile(result.next()) {\n   gs.info(\"Key: \" + result.getValue('key') + \", Value: \" + result.getValue('value'));\n}\n```\n\nOutput:\n\n```\nKey: title, Value: Add multiple attributes to an attachment\nKey: author, Value: Abel Tuter\nKey: category, Value: KB\nKey: length, Value: 5000\n```\n\n## GlideSysAttachment - copy\\(String sourceTable, String sourceID, String targetTable, String targetID\\)\n\nCopies attachments from the source record to the target record.\n\n**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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|sourceTable|String|Name of the table with the attachments to be copied.|\n|sourceID|String|Source table's sys\\_id.|\n|targetTable|String|Name of the table on which to add the attachments.|\n|targetID|String|The sys\\_id of the record in the target table on which to copy the attachment.|\n\n<table id=\"id_afm_yjz_g5b\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nArray of sys\\_ids of the attachments that were copied.Table: Attachments \\[sys\\_attachment\\]\n\n</td></tr></tbody>\n</table>This example shows how to copy attachments from an incident record to a problem record.\n\n```\nvar attachment = new GlideSysAttachment();\nvar incidentSysID = 'ab1b30031b04ec101363ff37dc4bcbfc';\nvar incGR = new GlideRecord('incident');\nincGR.get(incidentSysID);\n\nvar copiedAttachments = attachment.copy('incident', incidentSysID, 'problem', incGR.getValue('problem_id'));\ngs.info('Copied attachments: ' + copiedAttachments);\n```\n\nOutput:\n\n```\nCopied attachments: 6e4621df1bc420501363ff37dc4bcbb0,a87769531b0820501363ff37dc4bcba2\n```\n\n## GlideSysAttachment - deleteAllAttributes\\(\\)\n\nDeletes all attributes from an existing attachment record.\n\nSee also:\n\n-   [addAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n\nFor the scoped equivalent of this method, use [Scoped GlideSysAttachment - deleteAllAttributes\\(String sysAttachmentID\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_sql_3mg_5fc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the attributes were successfully deleted.Valid values:\n\n-   true: The attributes were successfully deleted.\n-   false: The attributes were not successfully deleted.\n\n</td></tr></tbody>\n</table>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.\n\n```\nvar attach = new GlideSysAttachment(\"04f48541083e2e50f877df7a115e31f3\");\n\nattach.deleteAllAttributes();\n\nvar result = attach.fetchAllAttributes();\n\nwhile(result.next()) {\n   gs.info(\"Key: \" + result.getValue('key') + \", Value: \" + result.getValue('value')); \n}\n```\n\nOutput:\n\n```\nAttribute \"null\" not found for attachment \"04f48541083e2e50f877df7a115e31f3\"\n\n```\n\n## GlideSysAttachment - deleteAttachment\\(String attachmentID\\)\n\nDeletes the specified attachment.\n\n**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.\n\n<table id=\"id_ywb_ykz_g5b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nattachmentID\n\n</td><td>\n\nString\n\n</td><td>\n\nAttachment's sys\\_id.Table: Attachments \\[sys\\_attachment\\]\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar attachment = new GlideSysAttachment();\nvar attachmentSysID = 'a87769531b0820501363ff37dc4bcba2';\nattachment.deleteAttachment(attachmentSysID);\n```\n\n## GlideSysAttachment - deleteAttribute\\(String attrKey\\)\n\nDeletes a specified attribute from attachment record.\n\nSee also:\n\n-   [addAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n\nFor the scoped equivalent of this method, use [Scoped GlideSysAttachment - deleteAllAttributes\\(String sysAttachmentID\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|attrKey|String|Key portion of a key-value pair for an attachment attribute.|\n\n<table id=\"table_sql_3mg_5fc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the attachment attribute was successfully deleted.Valid values:\n\n-   true: The attachment attribute was successfully deleted.\n-   false: The attachment attribute was not successfully deleted.\n\n</td></tr></tbody>\n</table>The following example shows how to delete an attribute assigned to a specified attachment with the key `author`. The results can also be verified in the Attachment Attributes \\[sys\\_attachment\\_attribute\\] table.\n\n```\nvar attach = new GlideSysAttachment(\"04f48541083e2e50f877df7a115e31f3v\");\n\nattach.deleteAttribute(\"author\");\n\nvar result = attach.fetchAttribute(\"author\");\n\nwhile(result.next()) {\n   gs.info(\"Key: \" + result.getValue('key') + \" \\nValue: \" + result.getValue('value')); \n}\n```\n\nOutput:\n\n```\nAttribute \"author\" not found for attachment \"04f48541083e2e50f877df7a115e31f3\"\n```\n\n## GlideSysAttachment - fetchAllAttributes\\(\\)\n\nFetches all attributes from a specified attachment record.\n\nSee also:\n\n-   [addAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n\nFor the scoped equivalent of this method, use [Scoped GlideSysAttachment - fetchAllAttributes\\(String sysAttachmentID\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|[GlideRecord](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)|The attachment record and all of its attributes.|\n\nThe following example shows how to get all attributes assigned to a specified attachment.\n\n```\nvar attach = new GlideSysAttachment(\"04f48541083e2e50f877df7a115e31f3\");\n\nvar result = attach.fetchAllAttributes();\n\nwhile(result.next()) {\n   gs.info(\"Key: \" + result.getValue('key') + \", Value: \" + result.getValue('value')); \n}\n```\n\nOutput:\n\n```\nKey: title, Value: Add multiple attributes to an attachment\nKey: author, Value: Abel Tuter\nKey: category, Value: KB\nKey: length, Value: 5000\n```\n\n## GlideSysAttachment - fetchAttribute\\(String attrKey\\)\n\nFetches a specified attribute from an attachment record.\n\nSee also:\n\n-   [addAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n\nFor the scoped equivalent of this method, use [Scoped GlideSysAttachment - fetchAttribute\\(String sysAttachmentID, String attrKey\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|attrKey|String|Key portion of a key-value pair for an attachment attribute.|\n\n|Type|Description|\n|----|-----------|\n|[GlideRecord](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)|The GlideRecord of the attachment and the specified attribute.|\n\nThe following example shows how to get an attachment attribute with the key `author`.\n\n```\nvar attach = new GlideSysAttachment(\"04f48541083e2e50f877df7a115e31f3\");\n\nvar result = attach.fetchAttribute(\"author\");\n\nwhile(result.next()) {\n   gs.info(\"Key: \" + result.getValue('key') + \" \\nValue: \" + result.getValue('value')); \n}\n```\n\nOutput:\n\n```\nKey: author \nValue: Abel Tuter\n```\n\n## GlideSysAttachment - getAttachments\\(String tableName, String sys\\_id\\)\n\nReturns a GlideRecord containing the matching attachment metadata such as name, type, or size.\n\n|Name|Type|Description|\n|----|----|-----------|\n|tableName|String|Name of the table to which the attachment belongs; for example, incident.|\n|sys\\_id|String|Sys\\_id of record to which the attachment belongs.|\n\n|Type|Description|\n|----|-----------|\n|GlideRecord|GlideRecord object containing the matching attachment metadata such as name, type, or size.|\n\nThe following script lists attachment file names for a record with two attachments.\n\n```\nvar attachment = new GlideSysAttachment();\n\nvar agr = attachment.getAttachments('<table_name>', '<record_sys_id>');\n\nwhile(agr.next())\ngs.info(agr.getValue('file_name'));\n```\n\nOutput:\n\n```\n*** Script: filename1.txt\n*** Script: filename2.txt\n```\n\n## GlideSysAttachment - getContentStream\\(String sysID\\)\n\nReturns a GlideScriptableInputStream object given the sys\\_id of an attachment.\n\nYou can use the [GlideTextReader](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideTextReaderScopedAPI.md) API to read the content stream.\n\n|Name|Type|Description|\n|----|----|-----------|\n|sysID|String|Attachment sys\\_id.|\n\n|Type|Description|\n|----|-----------|\n|GlideScriptableInputStream|Stream that contains the attachment content.|\n\n```\nvar attachment = new GlideSysAttachment();\nvar attachmentSysID = '6e4621df1bc420501363ff37dc4bcbb0';\nvar attachmentContentStream = attachment.getContentStream(attachmentSysID);\ngs.info('Attachment content stream: ' + attachmentContentStream);\n```\n\nOutput:\n\n```\nAttachment content stream: com.glide.communications.GlideScriptableInputStream@14bd299\n```\n\n## GlideSysAttachment - updateAllAttributes\\(Object attrsKeyValuePair\\)\n\nUpdates all the attributes for an existing attachment record.\n\nSee also:\n\n-   [addAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n\nFor the scoped equivalent of this method, use [Scoped GlideSysAttachment - updateAllAttributes\\(String sysAttachmentID, Object attrsKeyValuePair\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md).\n\n<table id=\"table_rql_3mg_5fc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nattrsKeyValuePair\n\n</td><td>\n\nObject\n\n</td><td>\n\nAttachment attributes in a set of key-value pairs. Each attribute key and its value must be provided as a string.For example:\n\n```\nvar attachmentAttributes = { \n    \"description\" : \"Photo of the solar system\",\n    \"dimensions\" : \"1600 x 300\"\n}\n```\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThe 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.\n\n```\nvar attach = new GlideSysAttachment(\"04f48541083e2e50f877df7a115e31f3\");\n\nvar attachmentAttributes = {\n    \"category\" : \"Training\",\n    \"title\" : \"Updating attachment attributes\", \n    \"author\" : \"Abraham Lincoln\",\n    \"length\" : \"6000\"\n}\n\nattach.updateAllAttributes(attachmentAttributes);\n\nvar result = attach.fetchAllAttributes();\n\nwhile(result.next()) {\n   gs.info(\"Key: \" + result.getValue('key') + \", Value: \" + result.getValue('value'));\n}\n```\n\nOutput:\n\n```\nKey: title, Value: Updating attachment attributes\nKey: author, Value: Abraham Lincoln\nKey: category, Value: Training\nKey: length, Value: 6000\n```\n\n## GlideSysAttachment - updateAttribute\\(String attrKey, String attrValue\\)\n\nUpdates a single attribute for an existing attachment record.\n\nSee also:\n\n-   [addAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md)\n\nFor the scoped equivalent of this method, use [Scoped GlideSysAttachment - updateAttribute\\(String sysAttachmentID, String attrKey, String attrValue\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|attrKey|String|Key portion of a key-value pair for an attachment attribute.|\n|attrValue|String|Value portion of a key-value pair for an attachment attribute.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to update an attribute assigned to a specified attachment with the key `author` and changes the value to Abel Tuter. The results can also be verified in the Attachment Attributes \\[sys\\_attachment\\_attribute\\] table.\n\n```\nvar attach = new GlideSysAttachment(\"04f48541083e2e50f877df7a115e31f3\");\n\nvar originalVal = attach.fetchAttribute(\"author\");\nwhile(originalVal.next()) {\n   gs.info(\"Original attribute value: \" + originalVal.getValue('value') + \"\\n\"); \n}\n\nattach.updateAttribute(\"author\", \"Abel Tuter\");\n\nvar updatedVal = attach.fetchAttribute(\"author\"); \nwhile(updatedVal.next()) {\n   gs.info(\"Updated attribute value: \" + updatedVal.getValue('value')); \n}\n```\n\nOutput:\n\n```\nOriginal attribute value: Fred Luddy\n\nUpdated attribute value: Abel Tuter\n```\n\n## GlideSysAttachment - write\\(GlideRecord record, String fileName, String contentType, String content\\)\n\nAttaches a specified attachment to the specified record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|record|GlideRecord|Record to which to attach the attachment.|\n|fileName|String|Attachment file name.|\n|contentType|String|MIME type of the attachment, such as `image/png`. Located in the Attachment \\[sys\\_attachment\\] table in the **Content type** field.|\n|content|String|Attachment content.|\n\n|Type|Description|\n|----|-----------|\n|String|Attachment sys\\_id. Returns null if the attachment was not added.|\n\n```\nvar attachment = new GlideSysAttachment();\n\n//set up inputs\nvar rec = new GlideRecord('incident');\nrec.get('78271e1347c12200e0ef563dbb9a7109');\nvar fileName = 'example.txt';\nvar contentType = 'text/csv';\nvar content = 'The text that is stored inside my file';\n\nvar agr = attachment.write(rec, fileName, contentType, content);\n\ngs.info('The attachment sys_id is: ' + agr);\n```\n\nOutput:\n\n```\nThe attachment sys_id is: 01271e4317c13311e0ef563dbb9abe34\n```\n\n## GlideSysAttachment - writeContentStream\\(GlideRecord now\\_GR, String fileName, String contentType, GlideScriptableInputStream inputStream\\)\n\nInserts an attachment using the input stream.\n\n|Name|Type|Description|\n|----|----|-----------|\n|now\\_GR|GlideRecord|Record to which to attach the attachment.|\n|fileName|String|Attachment file name.|\n|contentType|String|MIME type of the attachment, such as `image/png`. Located in the Attachment \\[sys\\_attachment\\] table in the **Content type** field.|\n|content|GlideScriptableInputStream|Attachment content.|\n\n|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the attachment created.|\n\nAttaches a content stream from the sys\\_attachment table to a test\\_table record.\n\n```\nfunction copyAttachmentToGlideRecord(conceptSysId) {\n\n  // Get record from test_table using sys_id\n  var targetGlideRecord = new GlideRecord(\"test_table\");\n  if (!targetGlideRecord.get(conceptSysId)) {\n     throw (\"Cannot find record created by test with sys_id: \" + conceptSysId);\n  }\n\n  // Get record from sys_attachment table\n  var sourceAttachmentGlideRecord = new GlideRecord('sys_attachment');    \n  sourceAttachmentGlideRecord.query();\n  sourceAttachmentGlideRecord.next();\n\n  // Get field values from retrieved sys_attachment record\n  var fileName = sourceAttachmentGlideRecord.getValue('file_name');\n  var contentType = sourceAttachmentGlideRecord.getValue('content_type');\n  var sourceAttachmentSysId = sourceAttachmentGlideRecord.getValue('sys_id');\n\n  // Attach sys_attachment record content stream to test_table record\n  var gsa = new GlideSysAttachment();\n  gsa.writeContentStream(\n    targetGlideRecord,\n    fileName,\n    contentType,\n    gsa.getContentStream(sourceAttachmentSysId));\n  gs.info(\"Attachment created\");\n}\n```\n\n"}}