- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 02:34 AM
Hello Team,
Can you tell me how to add attachment in incident when we create incident in one instance and send it to other instance with rest api.
Please help me with this.
Regards,
Nivedita
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2021 10:43 AM
Hi Nivedita,
here is the sample code that you can put in your BR of incident which will help you to push the attachment along with the incident to another instance.
(function executeRule(current, previous /*null when async*/ ) {
var body = {
"short_description": current.getValue("short_description"),
"description": current.getValue("description"),
"urgency": current.getValue("urgency"),
"impact": current.getValue("impact"),
"state": current.getValue("state")
};
try {
var r = new sn_ws.RESTMessageV2('Create_Incident', 'Create Incident');
r.setRequestBody(JSON.stringify(body));
var response = r.execute();
var responseBody = response.getBody();
var json = JSON.parse(responseBody);
var remoteInc_sys_id=json.result.sys_id;
var httpStatus = response.getStatusCode();
gs.log("Response status code is " + httpStatus);
if (httpStatus == "201") {
gs.log("Entered into the if conditon");
//Fetch attachment associated with the incident
var att = new GlideRecord("sys_attachment");
att.addQuery("table_sys_id", current.sys_id);
att.query();
//if you want to push all attachmetns, use while loop here
if (att.next()) {
var attachmentMessage = new sn_ws.RESTMessageV2();
attachmentMessage.setHttpMethod("post");
attachmentMessage.setBasicAuth("username", "password");
attachmentMessage.setEndpoint("https://devxxxxx.service-now.com/api/now/attachment/file");
attachmentMessage.setQueryParameter("table_name", att.table_name);
attachmentMessage.setQueryParameter("table_sys_id",remoteInc_sys_id);
attachmentMessage.setQueryParameter("file_name", att.file_name);
attachmentMessage.setRequestHeader("Content-Type", att.content_type);
attachmentMessage.setRequestHeader("Accept", "application/json");
attachmentMessage.setRequestBodyFromAttachment(att.sys_id);
response = attachmentMessage.execute();
responseBody = response.getBody();
httpStatus = response.getStatusCode();
}
}
} catch (ex) {
var message = ex.message;
}
})(current, previous);
Mark the comment as a correct answer and also helpful once worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 03:54 AM
Hi
you can use the eBonding Spoke. Please see https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/integrationhub/refere...
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 11:42 PM
Hi Maik,
I have used rest api to configure my integration between two service now instances.
Can you please tell me steps how can i implement attachment functionality in rest api to send attachment also while sending incident details.
Regards,
Nivedita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2021 12:29 AM
Hi Nivedita,
in case you don't want to or cannot use OOTB solutions you will have to implement a lot.
Plaese see similar questions for example: https://community.servicenow.com/community?id=community_question&sys_id=abfa0baddb5cdbc01dcaf3231f96...
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2021 04:56 AM
use the attachmenn API. fastest and Easy way. Only thing neeed is target system Sys ID which I am sure you are anyway storing when bondnig Incidents.
Once the correlation ID(target sys id) is available use BR to triger rest message using Attachment API
Let me know if you need a sample Attachment Rest Message