(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 StringUtil = new GlideStringUtil(); var file_name = att.file_name.toString(); var gsa = GlideSysAttachmentInputStream(att.sys_id.toString()); var baos = new Packages.java.io.ByteArrayOutputStream(); gsa.writeTo(baos); baos.close(); var base64EncodedData = StringUtil.base64Encode(baos.toByteArray()); sendRequest(base64EncodedData, 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);
Script to send attachment to third party from servicenow instance?
Working Code Asked question December 16, 2023