<?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 Integration attachement error: Response body was requested to be saved as attachment. It's not available through getBody() anymore. in ITSM forum</title>
    <link>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547616#M119395</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a script wich integrates Azure devops.&lt;/P&gt;
&lt;P&gt;When I add attachments from a specific group, it works well, but when I try with another group, the catch script returns: "Response body was requested to be saved as attachment. It's not available through getBody() anymore."&lt;/P&gt;
&lt;P&gt;But it doesnt make sense, as well it works with another group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Heres my code:&lt;/P&gt;
&lt;P&gt;var att2 = new GlideRecord('sys_attachment');&lt;BR /&gt; att2.addQuery('table_sys_id', incident.sys_id);&lt;BR /&gt; att2.addQuery('file_name', attchFilename.toString());&lt;BR /&gt; att2.query();&lt;BR /&gt; if (att2.next()) {&lt;BR /&gt; cckFileName2 = true;&lt;BR /&gt; } else {&lt;BR /&gt; cckFileName2 = false;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; if((!cckFileName) &amp;amp;&amp;amp; (!cckFileName2) &amp;amp;&amp;amp; (!comment.contains("Attachment from ServiceNow"))){&lt;BR /&gt;&lt;BR /&gt; //var check = new global.VSTSUtils().getAttachment(attachId, incident.sys_id, Mfilename.toString());&lt;BR /&gt; try {&lt;BR /&gt; var r = new sn_ws.RESTMessageV2('VSTS Integration BI', 'Get Attachments');&lt;BR /&gt; r.setStringParameterNoEscape('id', attachId);&lt;BR /&gt; r.saveResponseBodyAsAttachment('incident', incident.sys_id, Mfilename.toString());&lt;BR /&gt;&lt;BR /&gt; var response2 = r.execute();&lt;BR /&gt;&lt;BR /&gt; var responseBody = response2.getBody();&lt;BR /&gt;&lt;BR /&gt; var httpStatus = response2.getStatusCode();&lt;/P&gt;
&lt;P&gt;if (httpStatus == "200" || httpStatus == "201") {&lt;BR /&gt; }&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt; } catch (ex) {&lt;BR /&gt; var message = ex.message;&lt;BR /&gt; gs.log('catch: ' + message);&lt;BR /&gt; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anybody help me?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Wed, 24 Mar 2021 12:20:48 GMT</pubDate>
    <dc:creator>Giovana Lopes</dc:creator>
    <dc:date>2021-03-24T12:20:48Z</dc:date>
    <item>
      <title>Integration attachement error: Response body was requested to be saved as attachment. It's not available through getBody() anymore.</title>
      <link>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547616#M119395</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a script wich integrates Azure devops.&lt;/P&gt;
&lt;P&gt;When I add attachments from a specific group, it works well, but when I try with another group, the catch script returns: "Response body was requested to be saved as attachment. It's not available through getBody() anymore."&lt;/P&gt;
&lt;P&gt;But it doesnt make sense, as well it works with another group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Heres my code:&lt;/P&gt;
&lt;P&gt;var att2 = new GlideRecord('sys_attachment');&lt;BR /&gt; att2.addQuery('table_sys_id', incident.sys_id);&lt;BR /&gt; att2.addQuery('file_name', attchFilename.toString());&lt;BR /&gt; att2.query();&lt;BR /&gt; if (att2.next()) {&lt;BR /&gt; cckFileName2 = true;&lt;BR /&gt; } else {&lt;BR /&gt; cckFileName2 = false;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; if((!cckFileName) &amp;amp;&amp;amp; (!cckFileName2) &amp;amp;&amp;amp; (!comment.contains("Attachment from ServiceNow"))){&lt;BR /&gt;&lt;BR /&gt; //var check = new global.VSTSUtils().getAttachment(attachId, incident.sys_id, Mfilename.toString());&lt;BR /&gt; try {&lt;BR /&gt; var r = new sn_ws.RESTMessageV2('VSTS Integration BI', 'Get Attachments');&lt;BR /&gt; r.setStringParameterNoEscape('id', attachId);&lt;BR /&gt; r.saveResponseBodyAsAttachment('incident', incident.sys_id, Mfilename.toString());&lt;BR /&gt;&lt;BR /&gt; var response2 = r.execute();&lt;BR /&gt;&lt;BR /&gt; var responseBody = response2.getBody();&lt;BR /&gt;&lt;BR /&gt; var httpStatus = response2.getStatusCode();&lt;/P&gt;
&lt;P&gt;if (httpStatus == "200" || httpStatus == "201") {&lt;BR /&gt; }&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt; } catch (ex) {&lt;BR /&gt; var message = ex.message;&lt;BR /&gt; gs.log('catch: ' + message);&lt;BR /&gt; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anybody help me?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 12:20:48 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547616#M119395</guid>
      <dc:creator>Giovana Lopes</dc:creator>
      <dc:date>2021-03-24T12:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Integration attachement error: Response body was requested to be saved as attachment. It's not available through getBody() anymore.</title>
      <link>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547617#M119396</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Can you explain what it means it works for specific group?&lt;/P&gt;
&lt;P&gt;you can consuming 3rd party endpoint?&lt;/P&gt;
&lt;P&gt;So is there any specific thing you are sending which identifies the group&lt;/P&gt;
&lt;P&gt;please explain in detail with steps&lt;/P&gt;
&lt;P&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 12:46:35 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547617#M119396</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2021-03-24T12:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Integration attachement error: Response body was requested to be saved as attachment. It's not available through getBody() anymore.</title>
      <link>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547618#M119397</link>
      <description>&lt;P&gt;Hi, Ankur!&lt;/P&gt;
&lt;P&gt;Thanks for answer!!&lt;/P&gt;
&lt;P&gt;When I open an incident wich group is "A" or "B", it opens a work item in Azure devops.&lt;/P&gt;
&lt;P&gt;After that, when I try to send an attachment from ServiceNow to Azure, its all working.&lt;/P&gt;
&lt;P&gt;But when I send from azure to Servicenow, it works well with group "A", but when i send from group 'B', it doesnt work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope you understand me.&lt;/P&gt;
&lt;P&gt;Warn me if you have questions&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 14:46:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547618#M119397</guid>
      <dc:creator>Giovana Lopes</dc:creator>
      <dc:date>2021-03-24T14:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Integration attachement error: Response body was requested to be saved as attachment. It's not available through getBody() anymore.</title>
      <link>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547619#M119398</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;So what is the error message?&lt;/P&gt;
&lt;P&gt;what is the difference in both the JSON body when you send file for Group A and file for Group B?&lt;/P&gt;
&lt;P&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 15:06:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547619#M119398</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2021-03-24T15:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: Integration attachement error: Response body was requested to be saved as attachment. It's not available through getBody() anymore.</title>
      <link>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547620#M119399</link>
      <description>&lt;P&gt;Its the same JSON body for both&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error message is:&amp;nbsp;&lt;/P&gt;
&lt;H1 class="cm-content-title m-t"&gt;&lt;SPAN class="ng-binding" style="font-size: 7.5pt;"&gt;Response body was requested to be saved as attachment. It's not available through getBody() anymore.&lt;/SPAN&gt;&lt;/H1&gt;</description>
      <pubDate>Wed, 24 Mar 2021 17:03:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547620#M119399</guid>
      <dc:creator>Giovana Lopes</dc:creator>
      <dc:date>2021-03-24T17:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Integration attachement error: Response body was requested to be saved as attachment. It's not available through getBody() anymore.</title>
      <link>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547621#M119400</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;not much sure on this&lt;/P&gt;
&lt;P&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 04:45:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547621#M119400</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2021-03-25T04:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Integration attachement error: Response body was requested to be saved as attachment. It's not available through getBody() anymore.</title>
      <link>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547622#M119401</link>
      <description>&lt;P&gt;Yeah, this seems to be buggy as all get out.&amp;nbsp; When I create a REST service to table_list.do?CSV or table_list.do?EXCEL, it works fine when running a test, but no combination of the following works.&amp;nbsp; As you can see, the call to the rest service is parameterized as&amp;nbsp;the REST service's Default GET&amp;nbsp;has the proper ?CSV or ?EXCEL extension on the endpoint.&amp;nbsp; All other combinations seem to not work.&amp;nbsp; The 'text/html' appears to be that when run via script like below, you just get ServiceNow's html page response, but if you run directly in outbound REST as a test on Default GET method, it works.&amp;nbsp; Below I was switching between using saveResponseBodyAsAttachment vs. a GlideSystemAttachment.write().&amp;nbsp; Neither seem to work.&amp;nbsp;&amp;nbsp;saveResponseBodyAsAttachment gives a stack trace.&amp;nbsp;&amp;nbsp;GlideSystemAttachment.write() produces corrupted files. By the way, my REST Services are setup with basic auth to a service account and they have a full endpoint.&amp;nbsp; Partial or relative endpoints, i.e. "/table_list.do?EXCEL' do not work due to a 'host is null' error.&lt;/P&gt;
&lt;P&gt;vars passed in:&amp;nbsp; fileName, tableName, tableId.....&lt;/P&gt;
&lt;P&gt;var request = new sn_ws.RESTMessageV2(restName, restMethod);&lt;BR /&gt;request.saveResponseBodyAsAttachment(tableName, tableId, fileName); &lt;BR /&gt;response = request.execute();&lt;BR /&gt; if (response.getStatusCode() == '200') {&lt;BR /&gt; &lt;BR /&gt; var binaryFile = response.getBody();//Receiving excel file, binary data.&lt;BR /&gt; var attachment = new GlideSysAttachment();&lt;BR /&gt; var sqGr = new GlideRecord(tableName);&lt;BR /&gt; sqGr.get(sqTableId);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt; //attachment.writeBase64(sqGr, fileName, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", gs.base64Encode(binaryFile)); // corruption&lt;BR /&gt; //attachment.writeBase64(sqGr, fileName, "text/csv", binaryFile); // corruption&lt;BR /&gt; //attachment.write(sqGr, fileName, "text/csv", binaryFile); // this works for .CSV&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;Stack trace:&lt;/P&gt;
&lt;PRE&gt;Security restricted: MIME type mismatch for file: query_attachment3.csv. Expected type:text/csv, Actual type: text/html&lt;BR /&gt;Security restricted: File type is not allowed or does not match the content for file query_attachment3.csv&lt;BR /&gt;Evaluator: com.glide.rest.util.RESTRuntimeException: Response body was requested to be saved as attachment. It's not available through getBody() anymore.
   Caused by error in script at line 472
	com.glide.rest.outbound.direct.DirectRESTResponse.getBody(DirectRESTResponse.java:86)
	com.glide.rest.outbound.scriptable.ScriptableRESTResponse.jsFunction_getBody(ScriptableRESTResponse.java:82)
	sun.reflect.GeneratedMethodAccessor2549.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 May 2021 12:04:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547622#M119401</guid>
      <dc:creator>michaelward</dc:creator>
      <dc:date>2021-05-06T12:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: Integration attachement error: Response body was requested to be saved as attachment. It's not available through getBody() anymore.</title>
      <link>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547623#M119402</link>
      <description>&lt;P&gt;Joining in on having the issue.&lt;/P&gt;
&lt;P&gt;However i get the actual attachment created, but the REST message still fails with&amp;nbsp;&lt;BR /&gt;"Response body was requested to be saved as attachment. It's not available through getBody() anymore."&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jun 2021 19:27:26 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547623#M119402</guid>
      <dc:creator>kente</dc:creator>
      <dc:date>2021-06-27T19:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Integration attachement error: Response body was requested to be saved as attachment. It's not available through getBody() anymore.</title>
      <link>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547624#M119403</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;HTTP response is a stream that you cannot process twice.&amp;nbsp;saveResponseBodyAsAttachment is already processing the response and therefore you cannot do again&amp;nbsp;response.getBody();&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you possibly need to do is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var request = new sn_ws.RESTMessageV2(restName, restMethod);&lt;BR /&gt;response = request.execute();&lt;BR /&gt;if (response.getStatusCode() == '200') {&lt;BR /&gt;&lt;BR /&gt;var binaryFile = response.getBody();//Receiving excel file, binary data.&lt;BR /&gt;var attachment = new GlideSysAttachment();&lt;BR /&gt;var sqGr = new GlideRecord(tableName);&lt;BR /&gt;sqGr.get(sqTableId);&lt;/P&gt;
&lt;P&gt;// Write your own code to save the response Body as attachment&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jun 2021 02:46:13 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547624#M119403</guid>
      <dc:creator>Rahman3</dc:creator>
      <dc:date>2021-06-28T02:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: Integration attachement error: Response body was requested to be saved as attachment. It's not available through getBody() anymore.</title>
      <link>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547625#M119404</link>
      <description>&lt;P&gt;Hey, Thanks for this. It was very helpful in resolving the error.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 23:04:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/integration-attachement-error-response-body-was-requested-to-be/m-p/547625#M119404</guid>
      <dc:creator>Abhinav Duvvuri</dc:creator>
      <dc:date>2022-07-13T23:04:07Z</dc:date>
    </item>
  </channel>
</rss>

