<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: REST Attachment currupted file in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3228778#M1193310</link>
    <description>&lt;P&gt;Hello &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/53356"&gt;@jacobo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok I got it , there is some data here that's not to be in Excel. It's not decoding properly for Excel format. I am aware about&amp;nbsp; function maybe try that -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try below &lt;span class="lia-unicode-emoji" title=":backhand_index_pointing_down:"&gt;👇&lt;/span&gt; script -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var attachment = new GlideSysAttachment();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var agr = attachment.getAttachments('sc_req_item', 'ab480111c368ea9cda547fe4e4013143');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;while (agr.next()) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; gs.info(agr.getValue('file_name'));&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; gs.info(agr.getValue('sys_id'));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var Attachname = agr.getValue('file_name');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var attachmentSysId = agr.getValue('sys_id');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var bodyHeader = '';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; bodyHeader += '--' + boundary + '\r\n';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; bodyHeader += 'Content-Disposition: form-data; name="files"; filename="' + Attachname + '"\r\n';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; bodyHeader += 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\r\n\r\n';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var bodyFooter = '\r\n--' + boundary + '--\r\n';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var restMessage = new sn_ws.RESTMessageV2();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setHttpMethod('POST');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setLogLevel('all');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setEndpoint('External URL');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; // Set the first part of body&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setRequestBody(bodyHeader);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; // Attach the file content directly (raw binary)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setRequestBodyFromAttachment(attachmentSysId);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; // Append the footer manually (after the binary)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setStringParameterNoEscape('body_end', bodyFooter);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; try {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var response = restMessage.execute();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var responseBody = response.getBody();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.info('Response: ' + responseBody);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; } catch (e) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.error('Error sending Excel attachment: ' + e);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; break; // only handle the first attachment&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Regards,&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Shivalika&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;My LinkedIn - &lt;A href="https://www.linkedin.com/in/shivalika-gupta-540346194" target="_blank"&gt;https://www.linkedin.com/in/shivalika-gupta-540346194&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;My youtube - &lt;A href="https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&amp;amp;si=0WynLcOwNeEISQCY" target="_blank"&gt;https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&amp;amp;si=0WynLcOwNeEISQCY&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Apr 2025 21:59:23 GMT</pubDate>
    <dc:creator>Shivalika</dc:creator>
    <dc:date>2025-04-04T21:59:23Z</dc:date>
    <item>
      <title>REST Attachment currupted file</title>
      <link>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3228715#M1193291</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to send an excel file to an external API with post method. I'm using&amp;nbsp; this code to send it I have a successful result , the excel file is attached in the client environment (it is not servicenow)&lt;BR /&gt;When I try to download the attachemtent , excel can't open it beacuse the file is corrupted&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know what could be the possible error on my script?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;var attachment = new GlideSysAttachment();&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;var agr = attachment.getAttachments('sc_req_item', 'ab480111c368ea9cda547fe4e4013143');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;while(agr.next())&lt;/DIV&gt;&lt;DIV&gt;gs.info(agr.getValue('file_name'));&lt;/DIV&gt;&lt;DIV&gt;gs.info(agr.getValue('sys_id'));&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;var Attachname = agr.getValue('file_name');&lt;/DIV&gt;&lt;DIV&gt;var attachmentSysId = agr.getValue('sys_id');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;var attach=""&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;var is = new GlideSysAttachment().getContentStream(attachmentSysId);&lt;/DIV&gt;&lt;DIV&gt;var reader = new GlideTextReader(is);&lt;/DIV&gt;&lt;DIV&gt;var attachmentData = ' ';&lt;/DIV&gt;&lt;DIV&gt;while((attachmentData = reader.readLine()) != null) {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; // gs.log(attachmentData)&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;attach += attachmentData+"\r\n"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; // Define a boundary for the multipart/form-data request&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; var boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; // Build the multipart body string&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; var body = '';&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; // File part: adjust the "name" and "filename" as needed&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; body += '--' + boundary + '\r\n';&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; body += 'Content-Disposition: form-data; name="files"; filename="'+Attachname+'"\r\n';&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; body += 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\r\n\r\n';&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; // Append the file content. Note: if you need to send Base64 instead, retrieve and append Base64 content.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; body += attach;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; body += '\r\n';&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; // End boundary&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; body += '--' + boundary + '--\r\n';&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; // Create and configure the REST message&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; var restMessage = new sn_ws.RESTMessageV2();&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; restMessage.setHttpMethod('POST');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; restMessage.setLogLevel('all')&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; restMessage.setEndpoint(External URL);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; restMessage.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;gs.log(body)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; restMessage.setRequestBody(body);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; try {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Execute the REST call and log the response&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var response = restMessage.execute();&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var responseBody = response.getBody();&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.info('Response: ' + responseBody);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; } catch(e) {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.error('Error sending Excel attachment: ' + e);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Fri, 04 Apr 2025 20:18:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3228715#M1193291</guid>
      <dc:creator>jacobo</dc:creator>
      <dc:date>2025-04-04T20:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: REST Attachment currupted file</title>
      <link>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3228740#M1193296</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/53356"&gt;@jacobo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are using this script to post data on that side right ? WHy are you using the same script to download data on your end ? I mean were you also using the endpoint and tried downloading the attachment that's added.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, Question is unclear to me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Regards,&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Shivalika&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;My LinkedIn -&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://www.linkedin.com/in/shivalika-gupta-540346194" target="_blank" rel="nofollow noopener noreferrer"&gt;https://www.linkedin.com/in/shivalika-gupta-540346194&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;My youtube -&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&amp;amp;si=0WynLcOwNeEISQCY" target="_blank" rel="nofollow noopener noreferrer"&gt;https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&amp;amp;si=0WynLcOwNeEISQCY&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 20:43:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3228740#M1193296</guid>
      <dc:creator>Shivalika</dc:creator>
      <dc:date>2025-04-04T20:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: REST Attachment currupted file</title>
      <link>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3228770#M1193308</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the code to send the attachment then I will go to the user environment and I downloaded it manually&lt;/P&gt;&lt;P&gt;&amp;nbsp;but whe I try to open it , I have this error message&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jacobo_0-1743803058904.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/432556i0D3B10053D594134/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jacobo_0-1743803058904.png" alt="jacobo_0-1743803058904.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jacobo_1-1743803084137.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/432557iA9B297937E3EDE50/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jacobo_1-1743803084137.png" alt="jacobo_1-1743803084137.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't really what happened&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 21:45:33 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3228770#M1193308</guid>
      <dc:creator>jacobo</dc:creator>
      <dc:date>2025-04-04T21:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: REST Attachment currupted file</title>
      <link>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3228778#M1193310</link>
      <description>&lt;P&gt;Hello &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/53356"&gt;@jacobo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok I got it , there is some data here that's not to be in Excel. It's not decoding properly for Excel format. I am aware about&amp;nbsp; function maybe try that -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try below &lt;span class="lia-unicode-emoji" title=":backhand_index_pointing_down:"&gt;👇&lt;/span&gt; script -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var attachment = new GlideSysAttachment();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var agr = attachment.getAttachments('sc_req_item', 'ab480111c368ea9cda547fe4e4013143');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;while (agr.next()) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; gs.info(agr.getValue('file_name'));&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; gs.info(agr.getValue('sys_id'));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var Attachname = agr.getValue('file_name');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var attachmentSysId = agr.getValue('sys_id');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var bodyHeader = '';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; bodyHeader += '--' + boundary + '\r\n';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; bodyHeader += 'Content-Disposition: form-data; name="files"; filename="' + Attachname + '"\r\n';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; bodyHeader += 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\r\n\r\n';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var bodyFooter = '\r\n--' + boundary + '--\r\n';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var restMessage = new sn_ws.RESTMessageV2();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setHttpMethod('POST');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setLogLevel('all');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setEndpoint('External URL');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; // Set the first part of body&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setRequestBody(bodyHeader);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; // Attach the file content directly (raw binary)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setRequestBodyFromAttachment(attachmentSysId);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; // Append the footer manually (after the binary)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; restMessage.setStringParameterNoEscape('body_end', bodyFooter);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; try {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var response = restMessage.execute();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var responseBody = response.getBody();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.info('Response: ' + responseBody);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; } catch (e) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gs.error('Error sending Excel attachment: ' + e);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; break; // only handle the first attachment&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Regards,&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Shivalika&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;My LinkedIn - &lt;A href="https://www.linkedin.com/in/shivalika-gupta-540346194" target="_blank"&gt;https://www.linkedin.com/in/shivalika-gupta-540346194&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;My youtube - &lt;A href="https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&amp;amp;si=0WynLcOwNeEISQCY" target="_blank"&gt;https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&amp;amp;si=0WynLcOwNeEISQCY&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 21:59:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3228778#M1193310</guid>
      <dc:creator>Shivalika</dc:creator>
      <dc:date>2025-04-04T21:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: REST Attachment currupted file</title>
      <link>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3229399#M1193450</link>
      <description>&lt;P&gt;Hello &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/53356"&gt;@jacobo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Please confirm if you checked my answer. Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for my efforts and also it can move from unsolved bucket to solved bucket.&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Regards,&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Shivalika&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;My LinkedIn - &lt;A href="https://www.linkedin.com/in/shivalika-gupta-540346194" target="_blank"&gt;https://www.linkedin.com/in/shivalika-gupta-540346194&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;My youtube - &lt;A href="https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&amp;amp;si=0WynL" target="_blank"&gt;https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&amp;amp;si=0WynL&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;EM&gt;&lt;STRONG&gt;cOwNeE&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Apr 2025 03:51:56 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3229399#M1193450</guid>
      <dc:creator>Shivalika</dc:creator>
      <dc:date>2025-04-07T03:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: REST Attachment currupted file</title>
      <link>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3229426#M1193460</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/53356"&gt;@jacobo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it means the file data is not sent correctly.&lt;/P&gt;
&lt;P&gt;How does the 3rd party expect the file data base64encoded data or content stream?&lt;/P&gt;
&lt;P&gt;Did they share the sample JSON request body on how they expect the excel data?&lt;/P&gt;
&lt;P style="box-sizing: border-box; margin: 0px; color: #1d1d1d; font-family: Lato, Gilroy, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"&gt;there is a article explaining about using multi-part and providing the code:&amp;nbsp;&lt;A id="link_7" class="page-link lia-link-navigation lia-custom-event" style="box-sizing: border-box; background-color: transparent; color: #007393; text-decoration: underline; font-size: inherit;" href="https://www.servicenow.com/community/developer-articles/script-to-send-multipart-including-text-and-binary-restapi/ta-p/2315271" target="_blank" rel="noopener"&gt;Script to send multipart (including text and binary) RestAPI&lt;/A&gt;&lt;/P&gt;
&lt;P style="box-sizing: border-box; margin: 0px; color: #1d1d1d; font-family: Lato, Gilroy, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"&gt;And also there is a ready-to-use-solution in the Share:&amp;nbsp;&lt;A style="box-sizing: border-box; background-color: transparent; color: #007393; text-decoration: underline; font-size: inherit;" href="https://developer.servicenow.com/connect.do#!/share/contents/8774514_multipart_upload_helper?v=1.0&amp;amp;t=PRODUCT_DETAILS" target="_blank" rel="noopener noreferrer"&gt;MultiPart Upload Helper&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Apr 2025 04:06:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3229426#M1193460</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2025-04-07T04:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: REST Attachment currupted file</title>
      <link>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3230898#M1193813</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/53356"&gt;@jacobo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope you are doing good.&lt;/P&gt;
&lt;P&gt;Did my reply answer your question?&lt;/P&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 03:33:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3230898#M1193813</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2025-04-08T03:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: REST Attachment currupted file</title>
      <link>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3237457#M1195455</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I still have the same issue , I fund this KB article&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.servicenow.com/kb?id=kb_article_view&amp;amp;sysparm_article=KB0745010" target="_blank"&gt;https://support.servicenow.com/kb?id=kb_article_view&amp;amp;sysparm_article=KB0745010&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you think it would be works?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2025 21:52:53 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/rest-attachment-currupted-file/m-p/3237457#M1195455</guid>
      <dc:creator>jacobo</dc:creator>
      <dc:date>2025-04-14T21:52:53Z</dc:date>
    </item>
  </channel>
</rss>

