Pulling the attachments from third party system and inserting in servicenow

Palle
Tera Contributor

Hi SN Community, 

SOAP integration

I am pulling the attachments from thirdparty system using soap integration and wanted to insert in sys_attachment table. I am trying the below code to decode the blob and trying to insert using GlideSysAttachment API. (not using getBytes because it has the limitation of 5mb). Any help would be appreciated.

var stringUtil = new GlideStringUtil();
var att = new GlideSysAttachment();
var binary = new GlideSysAttachmentInputStream("Blob of the attachment"); // passing the blob of the attachment
var Sa = new Packages.java.io.ByteArrayOutputStream();
binary.writeTo(Sa,0,0); //// I am getting an error here: Evaluator: java.io.IOEXception: Stream closed
Sa.close();
var decode = StringUtil.base64DecodeAsBytes(Sa.toByteArray());
att.write(hlolsysId,attachment.file_name,attachment.content_type,decode);

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

you should use Attachment REST API to insert attachments in service now tables.

Use below sample code

 

// This is where we'll save the attachment
var tablenameB B  = 'incident';
var recordSysId = '8d6353eac0a8016400d8a125ca14fc1f';
var filenameB B B  = 'snlogo.png';

// Let's download the ServiceNow Logo
var logoUrl = 'https://instance.service-now.com/images/logos/logo_service-now.png';
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('get');
request.setEndpoint(logoUrl);

// Configure the request to save the response as an attachment
request.saveResponseBodyAsAttachment(tablename, recordSysId, filename);

// When we execute the request, the attachment will automatically be
// saved to the record we specified
var response = request.execute();
var httpResponseStatus = response.getStatusCode();
var httpResponseContentType = response.getHeader('Content-Type');
gs.debug("http response status_code: " + httpResponseStatus);
gs.debug("http response content-type: " + httpResponseContentType);

 

Regards,

Sachin

Hi Sachin, 

 

Thanks for the response, I missed adding to question, I already have existing SOAP integration between snow and thirdparty system. I am able to successfully retrieve it, but having issues in decoding the blob and inserting in sys_attachment table.

Community Alums
Not applicable

Hi Palle,

 

Were you able to achieve your requirement? If yes, pls do share the solution.