{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1034,"path":"api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md","title":"GlideSysAttachment - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideSysAttachment- Scoped\n\nThe GlideSysAttachment API provides methods to handle attachments.\n\nContent is returned as a string, not as a byte array when getContent\\(\\) is called.\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**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## Scoped GlideSysAttachment - GlideSysAttachment\\(\\)\n\nCreates an instance of the GlideSysAttachment class.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n## Scoped GlideSysAttachment - addAttribute\\(String sysAttachmentID, 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/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n\nFor the global equivalent of this method, use [GlideSysAttachment - addAttribute\\(String attrKey, String attrValue\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|sysAttachmentID|String|Sys\\_id of the attachment listed in the Attachments \\[sys\\_attachment\\] table.|\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();\nattach.addAttribute(\"9e1b714601932210f877b455304df0af\", \"author\", \"Fred Luddy\");\n\nvar result = attach.fetchAttribute(\"9e1b714601932210f877b455304df0af\", \"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## Scoped GlideSysAttachment - addMultipleAttributes\\(String sysAttachmentID, 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/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n\nFor the global equivalent of this method, use [GlideSysAttachment - addMultipleAttributes\\(Object attrsKeyValuePair\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.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\nsysAttachmentID\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the attachment listed in the Attachments \\[sys\\_attachment\\] table.\n\n</td></tr><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();\n\nvar attachmentID = '9e1b714601932210f877b455304df0af';\n\nvar attrsKeyValuePair = { };\n  attrsKeyValuePair[\"title\"]  = \"Add multiple attributes to an attachment\";\n  attrsKeyValuePair[\"category\"] =  \"KB\";\n  attrsKeyValuePair[\"length\"] =  \"5000\";\n\nattach.addMultipleAttributes(attachmentID, attrsKeyValuePair);\n\nvar result = attach.fetchAllAttributes(attachmentID);\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## Scoped 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_db3_wjz_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## Scoped GlideSysAttachment - deleteAllAttributes\\(String sysAttachmentID\\)\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/c_GlideSysAttachmentScopedAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n\nFor the global equivalent of this method, use [GlideSysAttachment - deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|sysAttachmentID|String|Sys\\_id of the attachment listed in the Attachments \\[sys\\_attachment\\] table.|\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();\n\nvar attachmentID = '9e1b714601932210f877b455304df0af';\n\nattach.deleteAllAttributes(attachmentID);\n\nvar result = attach.fetchAllAttributes(attachmentID);\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## Scoped 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_ajy_dlz_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|void| |\n\n```\nvar attachment = new GlideSysAttachment();\nvar attachmentSysID = 'a87769531b0820501363ff37dc4bcba2';\nattachment.deleteAttachment(attachmentSysID);\n```\n\n## Scoped GlideSysAttachment - deleteAttribute\\(String sysAttachmentID, 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/c_GlideSysAttachmentScopedAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n\nFor the global equivalent of this method, use [GlideSysAttachment - deleteAttribute\\(String attrKey\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|sysAttachmentID|String|Sys\\_id of the attachment listed in the Attachments \\[sys\\_attachment\\] table.|\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();\n\nvar attachmentID = '9e1b714601932210f877b455304df0af';\n\nattach.deleteAttribute(attachmentID, \"author\");\n\nvar result = attach.fetchAttribute(attachmentID, \"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## Scoped GlideSysAttachment - fetchAllAttributes\\(String sysAttachmentID\\)\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/c_GlideSysAttachmentScopedAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n\nFor the global equivalent of this method, use [GlideSysAttachment - fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|sysAttachmentID|String|Sys\\_id of the attachment listed in the Attachments \\[sys\\_attachment\\] table.|\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();\n\nvar attachmentID = '9e1b714601932210f877b455304df0af';\n\nvar result = attach.fetchAllAttributes(attachmentID);\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## Scoped GlideSysAttachment - fetchAttribute\\(String sysAttachmentID, 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/c_GlideSysAttachmentScopedAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n\nFor the global equivalent of this method, use [GlideSysAttachment - fetchAttribute\\(String attrKey\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|sysAttachmentID|String|Sys\\_id of the attachment listed in the Attachments \\[sys\\_attachment\\] table.|\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();\n\nvar attachmentID = '9e1b714601932210f877b455304df0af';\n\nvar result = attach.fetchAttribute(attachmentID, \"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## Scoped 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## Scoped GlideSysAttachment - getContent\\(GlideRecord sysAttachment\\)\n\nReturns the attachment content as a string.\n\nThis 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.\n\nThis method supports the following file types for attachments.\n\n-   CSV \\(\\*.csv\\)\n-   JSON \\(\\*.json\\)\n-   Text \\(\\*.txt\\)\n\n|Name|Type|Description|\n|----|----|-----------|\n|sysAttachment|GlideRecord|Attachment record.|\n\n|Type|Description|\n|----|-----------|\n|String|Attachment contents as a string. Returns up to 5MB of data.|\n\n```\nvar attachment = new GlideSysAttachment();\n\nvar agr = attachment.getAttachments('incident', '78271e1347c12200e0ef563dbb9a7109'); //create attachment GlideRecord\n\nwhile(agr.next()) { //for each attachment on the incident record\n   gs.info(agr.getValue('file_name')); //print file name of attachment\n   var attachmentContent = attachment.getContent(agr);\n   gs.info('Attachment content: ' + attachmentContent); //print attachment content\n}\n```\n\nOutput:\n\n```\nDoc1.txt\nAttachment content: I am text in a txt file attached to a record.\n```\n\n## Scoped GlideSysAttachment - getContentBase64\\(GlideRecord sysAttachment\\)\n\nReturns the attachment content as a string with base64 encoding.\n\nThis 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|sysAttachment|GlideRecord|Attachment record.|\n\n|Type|Description|\n|----|-----------|\n|String|Attachment contents as a string with base64 encoding. Returns up to 5MB of data.|\n\n```\nvar attachment = new GlideSysAttachment();\n\nvar agr = attachment.getAttachments('incident', '78271e1347c12200e0ef563dbb9a7109'); //create attachment GlideRecord\n\nwhile(agr.next()) { //for each attachment on the incident record\n   gs.info(agr.getValue('file_name')); //print file name of attachment\n   var attachmentContent = attachment.getContentBase64(agr);\n   gs.info('Attachment content: ' + attachmentContent); //print attachment content\n}\n```\n\nOutput:\n\n```\nDoc1.txt\nAttachment content: SSBhbSB0ZXh0IGluIGEgdHh0IGZpbGUgYXR0YWNoZWQgdG8gYSByZWNvcmQuIA0=\n```\n\n## Scoped 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## Scoped GlideSysAttachment - updateAllAttributes\\(String sysAttachmentID, 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/c_GlideSysAttachmentScopedAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n\nFor the global equivalent of this method, use [GlideSysAttachment - updateAllAttributes\\(Object attrsKeyValuePair\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.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\nsysAttachmentID\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the attachment listed in the Attachments \\[sys\\_attachment\\] table.\n\n</td></tr><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();\n\nvar attachmentID = '9e1b714601932210f877b455304df0af';\n\nvar attachmentAttributes = {\n    \"category\" : \"Training\",\n    \"title\" : \"Updating attachment attributes\", \n    \"author\" : \"Abraham Lincoln\",\n    \"length\" : \"6000\"\n}\n\nattach.updateAllAttributes(attachmentID, attachmentAttributes);\n\nvar result = attach.fetchAllAttributes(attachmentID);\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## Scoped GlideSysAttachment - updateAttribute\\(String sysAttachmentID, 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/c_GlideSysAttachmentScopedAPI.md)\n-   [addMultipleAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [deleteAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [fetchAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n-   [updateAllAttributes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSysAttachmentScopedAPI.md)\n\nFor the global equivalent of this method, use [GlideSysAttachment - updateAttribute\\(String attrKey, String attrValue\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideSysAttachmentGlobalAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|sysAttachmentID|String|Sys\\_id of the attachment listed in the Attachments \\[sys\\_attachment\\] table.|\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();\n\nvar attachmentID = '9e1b714601932210f877b455304df0af';\n\nvar originalVal = attach.fetchAttribute(attachmentID, \"author\");\nwhile(originalVal.next()) {\n   gs.info(\"Original attribute value: \" + originalVal.getValue('value') + \"\\n\"); \n}\n\nattach.updateAttribute(attachmentID, \"author\", \"Abel Tuter\");\n\nvar updatedVal = attach.fetchAttribute(attachmentID, \"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## Scoped 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## Scoped GlideSysAttachment - writeBase64\\(GlideRecord now\\_GR, String fileName, String contentType, String content\\_base64Encoded\\)\n\nInserts an attachment for the specified record using base64 encoded content.\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|String|Attachment content in base64 format.|\n\n|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the attachment created.|\n\n```\nvar attachment = new GlideSysAttachment();\n\nvar rec = new GlideRecord('incident');\nvar incidentSysID = 'ab1b30031b04ec101363ff37dc4bcbfc';\nrec.get(incidentSysID);\nvar fileName = 'example.txt';\nvar contentType = 'text/csv';\nvar base64Encodedcontent = 'SSBhbSB0ZXh0Lg==';\n\nvar agr = attachment.writeBase64(rec, fileName, contentType, base64Encodedcontent);\n\ngs.info('The attachment sys_id is: ' + agr);\n```\n\nOutput:\n\n```\nThe attachment sys_id is: 10cde9971b0820501363ff37dc4bcba6\n```\n\n## Scoped 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"}}