- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 03:36 AM
Hello Experts,
We are performing a third-party incident Integration, we need to send attachments to the third party while we create a new incident via business rule only.
we have written a business rule which has 2 fields: FileName & FileType through which we need to send the attachments to the third-party.
Can anyone help on how to send the attachments to the third-party through the below business rule.
Thanks in advance
Khozema Attar
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 06:38 AM
I am able to send attachment but after download that attachment that file(png) is not opening and differ in size
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 03:41 AM
Hi,
Below Link may be useful for your requirement:
Sending an attachment to ServiceNow via Web Services - ServiceNow Guru
ServiceNow Attachment Files via Web Service - YouTube
Attachment API - POST /now/attachment/upload
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 06:40 AM
Hi Sneha,
I was able to send attachments to third party .
But, as we are using SOAP for the integration ,attachments of size greater than 5MB are not transmitted.
So, Is there a way I can call REST API's POST method in my existing business rule to send attachments.
Find the Screenshot of the BR:
Thanks & Regards
Khozema
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 06:57 AM
Hi Khozema,
getBytes() method won't work for file more than 5MB. Use below code to getBytes() for any file which is less than 5MB or greater than 5MB
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", current.sys_id);
gr.addQuery("table_name", current.getTableName());
gr.query();
if (gr.next()){
var StringUtil = new GlideStringUtil();
var gsa = GlideSysAttachmentInputStream(gr.sys_id.toString());
var baos = new Packages.java.io.ByteArrayOutputStream();
gsa.writeTo(baos);
baos.close();
var base64EncodedData = StringUtil.base64Encode(baos.toByteArray());
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 07:13 AM
Hi Ankur Bawiskar,
Can you rectify my code according to your script:
(function executeRule(current, previous /*null when async*/) {
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', current.sys_id);
attachment.addQuery('table_name', current.getTableName());
attachment.query();
while (attachment.next()) {
sendAttachment(attachment);
}
function sendAttachment(att) {
try {
var sa = new GlideSysAttachment();
var binData = sa.getBytes(att);
var encData = GlideStringUtil.base64Encode(binData);
var file_name = att.file_name.toString();
sendRequest(encData, file_name);
} catch (Exception) {
gs.log('Failed sending Attachment to due to Exception: ' + Exception);
}
}
function sendRequest(encData, file_name) {
//Set up variables
s.setStringParameter('attachment.filename', file_name);
s.setStringParameter('attachment.type',encData);
}
})(current, previous);
Thanks & Regards
Khozema