
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 11:30 AM
I'm learning how to eBond from one SN instance to another using REST and Web Services tables, and am having some success, but I'm very frustrated trying to piece together the information I need to send attachments from an incident on the source to the corresponding incident on the target.
I have followed this post step by step, as it was the most straightforward solution I could find
https://servicenow-docs.readthedocs.io/en/latest/Sending_Attachments_via_REST/index.html
but it had some gaps that I've had to work through. I am to a point where attachments are getting sent from the source incident when expected, but they are sitting in a 'ready' state in the ecc_queue on the target instance. What else do I need to do to get them attached to the target incident?
There are probably better ways to do what I'm trying to do, but finding start-to-finish, step-by-step documentation has been fruitless and I have spent far too much time on this already.
Solved! Go to Solution.
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 01:20 PM
You can use below service now code to consume attachment aPI to POST attachments from one service now instance to another.
You need to create business rule on sys_attachment table to consume REST API from another instance to post attachment like below
(function executeRule(current, previous /*null when async*/) {
var grInc = new GlideRecord('incident');
if(grInc.get(current.table_sys_id)){
if(grInc.correlation_id != ''){ //if abc SN sys_id exists on the incident
try {
var r = new sn_ws.RESTMessageV2('xxx', 'POST');
r.setRequestHeader("Accept", "Application/json");
r.setRequestHeader("Content-Type", current.content_type);
r.setQueryParameter("table_sys_id", grInc.correlation_id);
r.setQueryParameter("file_name", current.file_name);
r.setQueryParameter("table_name", "sn_customerservice_case");
r.setRequestBodyFromAttachment(current.getUniqueValue()); //assign attachment to body
gs.log('[EBOND ATTACHMENT LOGS] - Attempting to POST the following attachment to the XYZ SN instance:\n'+current.file_name+', '+current.getUniqueValue()+', '+current.content_type);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var parser = new JSONParser();
var parsed = parser.parse(responseBody);
gs.log('[EBOND ATTACHMENT LOGS] - Attachment '+current.number+' pushed to XYZ SN instance into Case '+parsed.result.sys_target_sys_id.value+'.\nHTTP Status '+httpStatus);
gs.log('[EBOND ATTACHMENT LOGS] - Response:\n' + responseBody);
}
catch (ex) {
gs.log('[EBOND ATTACHMENT LOGS] Error in Attachment POST to XYZSN instance.\n' + ex.message);
}
}
}
})(current, previous);
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 11:33 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 12:46 PM
I've looked at all of this and there are still gaps from a newby perspective. The REST API Explorer only gives me cURL code samples when I choose binary POST or multipart form POST using the Attachment API. I'll try to sort through it again. *sigh*

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 01:20 PM
You can use below service now code to consume attachment aPI to POST attachments from one service now instance to another.
You need to create business rule on sys_attachment table to consume REST API from another instance to post attachment like below
(function executeRule(current, previous /*null when async*/) {
var grInc = new GlideRecord('incident');
if(grInc.get(current.table_sys_id)){
if(grInc.correlation_id != ''){ //if abc SN sys_id exists on the incident
try {
var r = new sn_ws.RESTMessageV2('xxx', 'POST');
r.setRequestHeader("Accept", "Application/json");
r.setRequestHeader("Content-Type", current.content_type);
r.setQueryParameter("table_sys_id", grInc.correlation_id);
r.setQueryParameter("file_name", current.file_name);
r.setQueryParameter("table_name", "sn_customerservice_case");
r.setRequestBodyFromAttachment(current.getUniqueValue()); //assign attachment to body
gs.log('[EBOND ATTACHMENT LOGS] - Attempting to POST the following attachment to the XYZ SN instance:\n'+current.file_name+', '+current.getUniqueValue()+', '+current.content_type);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var parser = new JSONParser();
var parsed = parser.parse(responseBody);
gs.log('[EBOND ATTACHMENT LOGS] - Attachment '+current.number+' pushed to XYZ SN instance into Case '+parsed.result.sys_target_sys_id.value+'.\nHTTP Status '+httpStatus);
gs.log('[EBOND ATTACHMENT LOGS] - Response:\n' + responseBody);
}
catch (ex) {
gs.log('[EBOND ATTACHMENT LOGS] Error in Attachment POST to XYZSN instance.\n' + ex.message);
}
}
}
})(current, previous);
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 01:52 PM
Thank you!!!! I was able to use this code to understand how to modify my business rule and it worked!