<h2>GlideSysAttachment - GlideSysAttachment()</h2><br/><div style="overflow-x:auto"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=UTF-8" /><meta name="copyright" content="(C) Copyright 2025" /><meta name="DC.rights.owner" content="(C) Copyright 2025" /><meta name="generator" content="DITA-OT" /><meta name="DC.type" content="concept" /><meta name="DC.title" content="GlideSysAttachment" /><meta name="abstract" content="The GlideSysAttachment API provides a way to handle attachments." /><meta name="description" content="The GlideSysAttachment API provides a way to handle attachments." /><meta name="DC.subject" content="Scoped GlideSysAttachment, GlideSysAttachment, copy(String sourceTable, String sourceID, String targetTable, String targetID), deleteAttachment(String attachmentID), getAttachments(), Scoped GlideSysAttachment, getContentStream( String sysID), GlideSysAttachment, write(GlideRecord record, String fileName, String contentType, String content), writeContentStream(GlideRecord gr, String fileName, String contentType, GlideScriptableInputStream inputStream)" /><meta name="keywords" content="Scoped GlideSysAttachment, GlideSysAttachment, copy(String sourceTable, String sourceID, String targetTable, String targetID), deleteAttachment(String attachmentID), getAttachments(), Scoped GlideSysAttachment, getContentStream( String sysID), GlideSysAttachment, write(GlideRecord record, String fileName, String contentType, String content), writeContentStream(GlideRecord gr, String fileName, String contentType, GlideScriptableInputStream inputStream)" /><meta name="DC.relation" scheme="URI" content="../../../../../build/applications/concept/api-server.html" /><meta name="DC.relation" scheme="URI" content="../../../../../build/applications/concept/api-implementation-reference.html" /><meta name="DC.relation" scheme="URI" content="../../../../../build/applications/concept/api-reference.html" /><meta name="DC.creator" content="ServiceNow" /><meta name="DC.date.created" content="2023-08-03" /><meta name="DC.date.modified" content="2023-08-03" /><meta name="DC.format" content="XHTML" /><meta name="DC.identifier" content="GlideSysAttachmentGlobalAPI" /><link rel="stylesheet" type="text/css" href="../../../../../CSS/commonltr.css" /><title>GlideSysAttachment</title></head><body> <div class="nested0" id="GlideSysAttachmentGlobalAPI"> <h1 class="title topictitle1" id="ariaid-title1">GlideSysAttachment </h1> <div class="body conbody"><p class="shortdesc">The <span class="keyword apiname">GlideSysAttachment</span> API provides a way to handle attachments.</p> <p class="p">Content is returned as a string, not as a byte array when <span class="keyword apiname">getContent()</span> is called.</p> <p class="p">Content is returned as a GlideScriptableInputStream object when <span class="keyword apiname">getContentStream()</span> is called. The GlideScriptableInputStream contains the actual bytes not converted into a String.</p> </div> <div class="related-links"> <div class="familylinks"> <div class="parentlink"><strong>Parent Topic:</strong> <a class="link" href="../../../../../build/applications/concept/api-server.html" title="Use server APIs in scripts to change the functionality of applications, or when you create new applications.">Server API reference</a></div> </div> </div><div class="topic reference nested1 api-method" id="GSA-copy_S_S_S_S"> <h2 class="title topictitle2" id="ariaid-title2">GlideSysAttachment - copy(String sourceTable, String sourceID, String targetTable, String targetID)</h2> <div class="body refbody"><p class="shortdesc">Copies attachments from the source record to the target record.</p> <div class="section" id="GSA-copy_S_S_S_S__section_jkp_dkz_g5b"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-copy_S_S_S_S__id_g4d_yjz_g5b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 1. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e155">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e158">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e161">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e155 ">sourceTable</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e158 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e161 ">Name of the table with the attachments to be copied.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e155 ">sourceID</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e158 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e161 ">Source table's sys_id.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e155 ">targetTable</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e158 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e161 ">Name of the table on which to add the attachments.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e155 ">targetID</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e158 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e161 ">Target table's sys_id.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-copy_S_S_S_S__id_afm_yjz_g5b" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 2. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e234">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e237">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e234 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e237 ">Array of sys_ids of the attachments that were copied.</td></tr></tbody></table> </div> </div> <div class="example" id="GSA-copy_S_S_S_S__id_i3w_yjz_g5b"> <pre class="pre codeblock"><code>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);</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>Copied attachments: 6e4621df1bc420501363ff37dc4bcbb0,a87769531b0820501363ff37dc4bcba2</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="GSA-deleteAttachment_S"> <h2 class="title topictitle2" id="ariaid-title3">GlideSysAttachment - deleteAttachment(String attachmentID)</h2> <div class="body refbody"><p class="shortdesc">Deletes the specified attachment.</p> <div class="section" id="GSA-deleteAttachment_S__section_clf_blz_g5b"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-deleteAttachment_S__id_ywb_ykz_g5b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 3. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e329">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e332">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e335">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e329 ">attachmentID</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e332 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e335 ">Attachment's sys_id.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-deleteAttachment_S__table_gjy_lyb_fv" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 4. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e372">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e375">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e372 ">void</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e375 "> </td></tr></tbody></table> </div> </div> <div class="example" id="GSA-deleteAttachment_S__id_nhc_zkz_g5b"> <pre class="pre codeblock"><code>var attachment = new GlideSysAttachment(); var attachmentSysID = 'a87769531b0820501363ff37dc4bcba2'; attachment.deleteAttachment(attachmentSysID);</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="GSA-getAttachments_S_S"> <h2 class="title topictitle2" id="ariaid-title4">GlideSysAttachment - getAttachments(String tableName, String sys_id)</h2> <div class="body refbody"><p class="shortdesc">Returns a GlideRecord containing the matching attachment metadata such as name, type, or size.</p> <div class="section" id="GSA-getAttachments_S_S__section_ekx_34y_g5b"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-getAttachments_S_S__id_m5v_14z_g5b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 5. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e461">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e464">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e467">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e461 ">tableName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e464 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e467 ">Name of the table to which the attachment belongs; for example, incident.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e461 ">sys_id</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e464 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e467 ">The sys_id of record to which the attachment belongs.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-getAttachments_S_S__id_qr3_c4z_g5b" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 6. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e516">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e519">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e516 ">GlideRecord</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e519 ">GlideRecord object containing the matching attachment metadata such as name, type, or size.</td></tr></tbody></table> </div> </div> <div class="example" id="GSA-getAttachments_S_S__id_jgc_d4z_g5b"> <p class="p">The following script lists attachment file names for a record with two attachments.</p> <pre class="pre codeblock"><code>var attachment = new GlideSysAttachment(); var agr = attachment.getAttachments('<table_name>', '<record_sys_id>'); while(agr.next()) gs.info(agr.getValue('file_name'));</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>*** Script: filename1.txt *** Script: filename2.txt</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="GSA-getContentStream_S"> <h2 class="title topictitle2" id="ariaid-title5">GlideSysAttachment - getContentStream(String sysID)</h2> <div class="body refbody"><p class="shortdesc">Returns a GlideScriptableInputStream object given the sys_id of an attachment.</p> <div class="section" id="GSA-getContentStream_S__section_iy2_ppy_g5b"> <p class="p">You can use the <a class="xref" href="../../GlideTextReaderScoped/concept/c_GlideTextReaderScopedAPI.html" title="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.">GlideTextReader</a> API to read the content stream.</p> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-getContentStream_S__id_sdc_44z_g5b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 7. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e624">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e627">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e630">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e624 ">sysID</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e627 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e630 ">Attachment sys_id.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-getContentStream_S__id_nqx_44z_g5b" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 8. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e667">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e670">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e667 ">GlideScriptableInputStream</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e670 ">Stream that contains the attachment content.</td></tr></tbody></table> </div> </div> <div class="example" id="GSA-getContentStream_S__id_vkn_p4z_g5b"> <pre class="pre codeblock"><code>var attachment = new GlideSysAttachment(); var attachmentSysID = '6e4621df1bc420501363ff37dc4bcbb0'; var attachmentContentStream = attachment.getContentStream(attachmentSysID); gs.info('Attachment content stream: ' + attachmentContentStream);</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>Attachment content stream: com.glide.communications.GlideScriptableInputStream@14bd299</code></pre> </div> </div> </div> <div class="topic reference nested1 api-constructor" id="GSA-GlideSysAttachment"> <h2 class="title topictitle2" id="ariaid-title6">GlideSysAttachment - GlideSysAttachment()</h2> <div class="body refbody"><p class="shortdesc">Creates an instance of the GlideSysAttachment class.</p> <div class="section" id="GSA-GlideSysAttachment__section_cdt_sqz_g5b"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-GlideSysAttachment__table_iys_ctb_fv" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 9. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e763">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e766">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e769">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e763 ">None</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e766 "> </td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e769 "> </td></tr></tbody></table> </div> </div> </div> </div> <div class="topic reference nested1 api-method" id="GSA-write_GR_S_S_S"> <h2 class="title topictitle2" id="ariaid-title7">GlideSysAttachment - write(GlideRecord record, String fileName, String contentType, String content)</h2> <div class="body refbody"><p class="shortdesc">Attaches a specified attachment to the specified record.</p> <div class="section" id="GSA-write_GR_S_S_S__section_chw_z4z_g5b"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-write_GR_S_S_S__id_odn_1pz_g5b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 10. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e850">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e853">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e856">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e850 ">record</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e853 ">GlideRecord</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e856 ">Record to which to attach the attachment.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e850 ">fileName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e853 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e856 ">Attachment file name.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e850 ">contentType</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e853 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e856 ">Attachment content type.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e850 ">content</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e853 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e856 ">Attachment content.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-write_GR_S_S_S__id_kbx_1pz_g5b" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 11. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e929">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e932">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e929 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e932 ">Attachment sys_id. Returns null if the attachment was not added.</td></tr></tbody></table> </div> </div> <div class="example" id="GSA-write_GR_S_S_S__id_h3q_cpz_g5b"> <pre class="pre codeblock"><code>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);</code></pre> <p class="p">Output:</p> <pre class="pre codeblock"><code>The attachment sys_id is: 01271e4317c13311e0ef563dbb9abe34</code></pre> </div> </div> </div> <div class="topic reference nested1 api-method" id="GSA-writeContentStrm_GR_S_S_GSIS"> <h2 class="title topictitle2" id="ariaid-title8">GlideSysAttachment - writeContentStream(GlideRecord now_GR, String fileName, String contentType, GlideScriptableInputStream inputStream)</h2> <div class="body refbody"><p class="shortdesc">Inserts an attachment using the input stream.</p> <div class="section" id="GSA-writeContentStrm_GR_S_S_GSIS__section_lpt_3pz_g5b"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-writeContentStrm_GR_S_S_GSIS__id_trk_jpz_g5b" class="table parameters" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 12. </span>Parameters</span></caption><colgroup><col /><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e1025">Name</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e1028">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e1031">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1025 ">now_GR</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1028 ">GlideRecord</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1031 ">Record to which the attachment is to be attached.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1025 ">fileName</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1028 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1031 ">Attachment's file name.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1025 ">contentType</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1028 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1031 ">Attachment's content type.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1025 ">content</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1028 ">GlideScriptableInputStream</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1031 ">Attachment content.</td></tr></tbody></table> </div> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="GSA-writeContentStrm_GR_S_S_GSIS__id_ncv_jpz_g5b" class="table returns" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 13. </span>Returns</span></caption><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e1104">Type</th><th class="entry cellrowborder" style="vertical-align:top;" id="d880222e1107">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1104 ">String</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d880222e1107 ">Sys_id of the attachment created.</td></tr></tbody></table> </div> </div> <div class="example" id="GSA-writeContentStrm_GR_S_S_GSIS__id_b4p_kpz_g5b"> <p class="p">Attaches a content stream from the sys_attachment table to a test_table record.</p> <pre class="pre codeblock"><code>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"); }</code></pre> </div> </div> </div> </div> </body></html></div>