Send the attachment to third party using scripted API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 12:46 AM
Hello,
I want to send the incident(if it is a new incident) attachment from ServiceNow to a third party using Scripted REST API.
Could anyone please look into this and help me with this?
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 12:56 AM
Hi @Rama Rao.,
1. You can make use of table API (Attachement), why scripted rest ?
2. you can create a business rule on attachement table on insert with conditon table is incident.
3. Create REST api MESSAGE and Method to pass the file using base64 encode if the 3rd party supports of not go for other method.
i hope this helps..
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 01:22 AM
Hello @Sohail Khilji ,
We have a requirement to send attachments to a third party using Scripted REST API
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 01:14 AM
Hi @Rama Rao
Scripted Rest API could be used to receive the attachment in Servicenow. In order to send the attachment to third party, you need to create REST message and write a Business Rule.
Have you created REST message? If not, you can use the following business rule script to send the attachment alternatively-
var incidentSysId = current.sys_id.toString();
var attachmentRecord = new GlideRecord('sys_attachment');
attachmentRecord.addQuery('table_sys_id', incidentSysId);
attachmentRecord.query();
if (attachmentRecord.next()) {
var attachmentSysId = attachmentRecord.sys_id.toString();
// Prepare RESTMessageV2 for the API call
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod('post');
restMessage.setEndpoint('YOUR_ENDPOINT_URL'); // Set your REST endpoint URL
restMessage.setRequestHeader("Content-Type", "application/json");
// Additional headers like Authorization as needed
// restMessage.setRequestHeader("Authorization", "Bearer YOUR_ACCESS_TOKEN");
var requestBody = {
"incidentSysId": incidentSysId,
"attachmentSysId": attachmentSysId
// Populate as per the API requirements
};
restMessage.setRequestBody(JSON.stringify(requestBody));
try {
var response = restMessage.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
// Handle the response, parse JSON, etc.
gs.info("REST call successful: " + responseBody);
} catch (ex) {
var errorMsg = ex.getMessage();
gs.error("REST call error: " + errorMsg);
}
}
}
Please mark my answer helpful and correct.
Regards,
Amit