- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2021 05:20 AM
Hello,
I have a script wich integrates Azure devops.
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."
But it doesnt make sense, as well it works with another group.
Heres my code:
var att2 = new GlideRecord('sys_attachment');
att2.addQuery('table_sys_id', incident.sys_id);
att2.addQuery('file_name', attchFilename.toString());
att2.query();
if (att2.next()) {
cckFileName2 = true;
} else {
cckFileName2 = false;
}
if((!cckFileName) && (!cckFileName2) && (!comment.contains("Attachment from ServiceNow"))){
//var check = new global.VSTSUtils().getAttachment(attachId, incident.sys_id, Mfilename.toString());
try {
var r = new sn_ws.RESTMessageV2('VSTS Integration BI', 'Get Attachments');
r.setStringParameterNoEscape('id', attachId);
r.saveResponseBodyAsAttachment('incident', incident.sys_id, Mfilename.toString());
var response2 = r.execute();
var responseBody = response2.getBody();
var httpStatus = response2.getStatusCode();
if (httpStatus == "200" || httpStatus == "201") {
}
} catch (ex) {
var message = ex.message;
gs.log('catch: ' + message);
}
Can anybody help me?
Thank you
Solved! Go to Solution.
- Labels:
-
Incident Management
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2021 07:46 PM
Hello,
HTTP response is a stream that you cannot process twice. saveResponseBodyAsAttachment is already processing the response and therefore you cannot do again response.getBody();
What you possibly need to do is this:
var request = new sn_ws.RESTMessageV2(restName, restMethod);
response = request.execute();
if (response.getStatusCode() == '200') {
var binaryFile = response.getBody();//Receiving excel file, binary data.
var attachment = new GlideSysAttachment();
var sqGr = new GlideRecord(tableName);
sqGr.get(sqTableId);
// Write your own code to save the response Body as attachment
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2021 05:46 AM
Hi,
Can you explain what it means it works for specific group?
you can consuming 3rd party endpoint?
So is there any specific thing you are sending which identifies the group
please explain in detail with steps
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2021 07:46 AM
Hi, Ankur!
Thanks for answer!!
When I open an incident wich group is "A" or "B", it opens a work item in Azure devops.
After that, when I try to send an attachment from ServiceNow to Azure, its all working.
But when I send from azure to Servicenow, it works well with group "A", but when i send from group 'B', it doesnt work
I hope you understand me.
Warn me if you have questions
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2021 08:06 AM
Hi,
So what is the error message?
what is the difference in both the JSON body when you send file for Group A and file for Group B?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2021 10:03 AM
Its the same JSON body for both
The error message is: