
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 05:57 AM
Hello everybody!
Does any one have any idea how to send a servicenow record from one instance to another? I have tried everything, but It just won't work!
I've been receiving errors on octet-stream type or even the file type. I put the code bellow:
sendAttachment: function(ticket, record) {
try {
var output = {
hasError: false
};
// CARREGA anexo do registro indicado
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('sys_id', record);
attachmentGR.query();
if (attachmentGR.next()) {
var fileName = attachmentGR.file_name.toString();
var contentType = attachmentGR.content_type;
var attachmentSysId = attachmentGR.sys_id;
}
// Recupera o binário do anexo
var stream = new GlideSysAttachmentInputStream(attachmentSysId);
var byteStream = new Packages.java.io.ByteArrayOutputStream();
stream.writeTo(byteStream, 0, 0);
var request = new sn_ws.RESTMessageV2();
request.setEndpoint(this.baseurl + '/api/now/attachment/file?table_name=incident&table_sys_id=' + ticket + '&file_name=' + encodeURIComponent(fileName));
request.setHttpMethod('POST');
request.setBasicAuth(this.username, this.password);
request.setRequestHeader('Content-Type', contentType);
request.setRequestHeader('Accept', 'application/json');
request.setRequestBody(byteStream.toByteArray());
var response = request.execute();
var httpStatus = response.getStatusCode();
var responseBody = response.getBody();
if (httpStatus < 200 || httpStatus >= 300) {
throw output;
}
return output;
} catch (error) {
output.hasError = true;
output.httpStatus = httpStatus;
output.errorMessage = responseBody;
}
}
I have sucessfuly send a file, but it's content get on the other side broken. If I use the content type of the table, some times it gets a file type error
I have tried to mount a multipart sending too, but it fails!
Any help would be appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 06:08 AM
And lastly, is this one-time transfer or do you aim to do it regularly?
For the one-timer it might be possible to export it (but still the target record must be defined).
Debug: check the target sys_attachment table, perhaps the record is there you just cannot see it in any form as the associated sys ID will be unknown.
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 06:01 AM
Olá @BRUNO BANDEIRA,
you can think of the attachment as a record in [sys_attachment] table, it has its sys ID and sys ID of the record where it is stored at.
If you want to share it, maybe sending XML/JSON from this table to another would be easier.
But my question is if I have an attachment "document.txt" in instance 1 and I want to move it to instance 2, how that shall work? The attachments are associated with a record and even the same document attached to to 3 different records (e.g. the very same "document.txt" is attached to 3 different incidents) will be in the sys_attachment table, so where do you expect to see it in the target instance?
And also, what format are we talking about - pictures, text document, excel sheets, xml, .....?
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 06:05 AM
I didn't say it all perhaps..
The sys_attachment records is for example associated with an incident that doesn't exist in the target table... so you either need to move it with that or think of any fallback how to move it.
- Instance 1:
- INC0001 has attachment "document.txt", with sys ID "1234"
- Instance 2:
- INC0001 with sys ID "5678" cannot be associated.
Attachment is associated with the first Instance's data, is this managed in your script? to tell it where shall the attachment be put?
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2025 06:08 AM
And lastly, is this one-time transfer or do you aim to do it regularly?
For the one-timer it might be possible to export it (but still the target record must be defined).
Debug: check the target sys_attachment table, perhaps the record is there you just cannot see it in any form as the associated sys ID will be unknown.
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 01:50 PM
I could make ir work @GlideFather!
Thank you for your suport!