Send Attachment from Servicenow to Salesforce using OOB Salesforce Spoke

Rocky5
Kilo Sage

Hello All,

 

We are implementing the integration between Servicenow and Salesforce, And using flow designer (below screenshot) and using oob salesforce spoke we are sending data to Salesforce which will create a record in salesforce. Now, we also want to send attachment to the salesforce along with data.. so that attachment is attached to the record created in salesforce. How can I achieve that? how can we send attachments to salesforce?


Below is the Flow where 'Create Record' action creates record in Salesforce. 

Rocky5_0-1694115782345.png

 


Thanks,

Rocky.

1 REPLY 1

Edward Hall1
Tera Contributor

Here is my contribution.... if there is a javascript person out there to give some proper order to the script step, I think this will work...it is close - I have the SF RecordID stored in the related task record correlation ID-

EdwardHall1_0-1696473812543.pngEdwardHall1_1-1696473950342.png

(function execute(inputs, outputs) {

var requestObjTask = {};
requestObjTask.number = inputs.number.toString();
requestObjTask.correlation_id = inputs.correlation_id.toString();
requestObjTask.attachments = [];

//var attachmentData = {};
var grattach = new GlideRecord('sys_attachment');
grattach.addQuery('sys_id',inputs.sys_ids);
grattach.query();
if(grattach.next()){
//gs.log('flow if');
var sa = new GlideSysAttachment();
//gs.log('success1');
var binData = sa.getBytes(grattach);
//gs.log('success2');
var base64Data = GlideStringUtil.base64Encode(binData);
//gs.log('success3');
var attachmentData = {};
attachmentData.attachment = {};
attachmentData.attachment.filename = grattach.file_name.toString();
attachmentData.attachment.file= base64Data.toString(); // remove substring
requestObjTask.attachments.push(attachmentData);

}
// gs.log('reqobjtask'+JSON.stringify(requestObjTask));
outputs.ritmreqbody =JSON.stringify(requestObjTask);

})(inputs, outputs);

EdwardHall1_2-1696474132727.png