INTEGRATION CHERWELL X SERVICENOW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 11:57 AM
Hello guys!
I am in need for some help with a Cherwell ITSM and Service Now platform. If anybody could give me a hand it wilol be very apreciated!
I have create a ticket without any fuzz, but when it comed to sending attachments to the platform, I have been facing some issues. Bellow I put the scripts background used to send the file:
***
var current = 'bc1d019087cdead0f99832680cbb359d'; // SNOW record
var ticket = {NUMBER}
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_sys_id', current);
attachmentGR.addQuery('table_name', 'sn_si_incident');
attachmentGR.query();
if (attachmentGR.next()) {
var parts = attachmentGR.file_name.split('.');
var ext = parts.pop();
var name = parts.join('.').toLowerCase().replace(/[^a-zA-Z0-9]/g, '_');
var file_name = name + '.' + ext; // Formated filename
var file_size = attachmentGR.size_bytes.toString();
var sa = new GlideSysAttachment();
var byteArray = sa.getBytes(attachmentGR); // Binary
var request = new sn_ws.RESTMessageV2();
var endpoint = '{{baseUrl}}/api/V1/uploadbusinessobjectattachment/filename/' + encodeURIComponent(file_name) + '/busobid/6dd53665c0c24cab86870a21cf6434ae/busobrecid/' + ticket + '/offset/0/totalsize/' + file_size;
request.setEndpoint(endpoint);
request.setHttpMethod('POST');
request.setRequestHeader('Authorization', 'Bearer ' + token);
request.setRequestHeader('Content-Type', 'application/octet-stream');
request.setLogLevel('all');
request.setRequestBody(byteArray); // Sending Binary
var response = request.execute();
var httpStatus = response.getStatusCode();
var responseBody = response.getBody();
gs.info('HTTP STATUS: ' + httpStatus);
gs.info('RESPONSE BODY: ' + responseBody);
}
***
At first, I was receiving the error bellow, and I guess is something about the file size, and I just used two approaches: Get the SIZE BYTES directly from table SYS_ATTACHMENT, like above and take the byteArray.length value.
*** Script: HTTP STATUS: 400
*** Script: RESPONSE BODY: {"attachments":[],"errorCode":"BADREQUEST","errorMessage":"Size of data uploaded (plus specified offset) is greater than the specified totalsize for the file.","hasError":true,"httpStatusCode":400}
***
Finally, it looked the table version works better, and I have stopped to received the error. and start to get a 202 message, but, the file isn't get attached to the ticket. I have received the message bellow:
*** Script: HTTP STATUS: 202
*** Script: RESPONSE BODY: "94bc01988e6ad23e6b5c34439ab4d6ffa78aa4a9e0"
In theory, everything runs smootly, but the attachment just don't appear...
If anyone could point me to the right direction it will be great!
Thanks in advance!