Send Attachment from Servicenow to Salesforce using OOB Salesforce Spoke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 12:43 PM
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.
Thanks,
Rocky.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 07:52 PM
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-
(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);