- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2020 09:53 AM
I have been unable to send attachments via REST. The call sends data from an incident task table to an external system with no problems until I try to add the attachment. When I do, the Outbound HTTP Requests log shows a 200 message but the URL/endpoint is "http://snap/snap/scanrequest."
I am trying to add "setRequestBodyFromAttachment." Ideally, I'd like to be able to use it here:
(function executeRule(current, previous /*null when async*/) {
try {
// Stops line breaks in journaling fields
var workinfo=current.work_notes.getJournalEntry(1).toString();
var notesarry = workinfo.split("\n");
var wnote=notesarry[1];
var comments=current.comments.getJournalEntry(1).toString();
var commentssarry = comments.split("\n");
var cnote=commentssarry[1];
// Stops line breaks in journaling fields
var r = new sn_ws.RESTMessageV2('------------', '------------');
r.setStringParameterNoEscape('number', current.number);
r.setStringParameterNoEscape('u_vendor_ref_no', current.u_vendor_ref_no);
r.setStringParameterNoEscape('state', current.state.getDisplayValue());
r.setStringParameterNoEscape('cmdb_ci', current.cmdb_ci.getDisplayValue());
r.setStringParameterNoEscape('assignment_group', current.assignment_group.getDisplayValue());
r.setStringParameterNoEscape('work_notes', wnote);
//r.setStringParameterNoEscape('comments', cnote);
r.setStringParameterNoEscape('sys_id', current.sys_id.toString());
r.setStringParameterNoEscape('u_am_location', current.u_am_location.getDisplayValue());
r.setStringParameterNoEscape('short_description', current.short_description);
r.setStringParameterNoEscape('u_am_email', current.u_caller.email.getDisplayValue());
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
})(current, previous);
I have tried just adding the attachment separate function in same Business Rule and when I do, it sends the incident data but does not send the attachment:
(function amRESTMessageV2() {
try {
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('post');
request.setEndpoint('----------');
request.setRequestBodyFromAttachment('----------');
var response = request.execute();
var httpResponseStatus = response.getStatusCode();
gs.print("http response status_code: " + httpResponseStatus);
}
catch (ex) {
var message = ex.getMessage();
gs.print(message);
}
})();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 01:37 PM
That makes sense, but I'm not sure the problem is getting the attachment.
When I attach a document and check Outbound HTTP Requests, I only show it attempting to POST to http://snap/snap/scanrequest. The Response status is always 200 and the Request Length is different. If I remove/comment out the parts that try to send the attachment from the business rule, it sends the message to the correct endpoint.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 11:38 PM
Hi,
I believe you need to include that attachment content in the body.
please refer the links shared
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
07-29-2020 03:09 PM
I can research my original problem later but your solution definitely worked. I appreciate it!!-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2020 10:34 PM
Glad that my approach worked.
Would you mind marking my response as correct & helpful if I am able to help you.
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
08-10-2020 05:17 AM
Glad that my approach worked.
Would you mind marking my response as correct & helpful if I am able to help you.
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
09-30-2020 04:12 AM
Glad that my approach worked.
Would you mind marking my response as correct & helpful if I am able to help you.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader