send multiple attachments as part of REST message via flow designer

Priyadharashin1
Tera Contributor

Hi All,

I have a requirement to send multiple attachments from an incident record as Binary files to a 3rd party from flow designer. I am using REST message with content type as application/octet-stream. For a single file, its working fine but for multiple attachments, the response shows error invalid content type. Below is the code:

var attachments=[];
var fileName=[];
var i=0;
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', inputs.inc_sys_id);
gr.addQuery('table_name', 'incident');
gr.query();
while(gr.next()){
var file = gr.getValue('file_name').toString();
fileName.push(file);
}
for(var i=0;i<fileName.length;i++){
var GRattach = new GlideRecord('sys_attachment');
GRattach.addQuery('file_name',fileName[i]);
GRattach.query();
if(GRattach.next()){
var sa = new GlideSysAttachment();
var fileContent = sa.getContent(GRattach).toString();
attachments.push(fileContent);
}
}
outputs.file_name = fileName;
outputs.content = attachments;

 

I am getting the fileName and content as an array but something is not working when i try to send the payload.

 

 

2 REPLIES 2

Raju86866
Tera Contributor

Hi Priyadarshan,

 

How did you accomplish this requirement?

Hi @Raju86866 ,

 

I created a flow on the Attachment table. And I created an action to call the REST method. In the REST step, content type is set to Binary and pass the sys_id of the attachment record. So, when a record is created in the attachment table, the action will run and send the payload.

 

Hope this helps.