How to Create an api for the multiple attachment

rohit_hatkar1
Tera Expert

Hello Experts,

I need an api from the ServiceNow to add the multiple attachments to the incident record

I checked in the Api explorer but no luck.

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron

@rohit_hatkar1 

ServiceNow OOTB Attachment API doesn't support multiple files

You can create Scripted REST API and ask 3rd party to send array of JSON object and then handle it using customization.

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

Hi  @Ankur Bawiskar ,

Thank you for the response. I am trying to create the attachment using the AttachmentCreator in the ecc queu. Using the below code create an attachment but the problem is for docs and excel it is not working. 

 

var parentTable = '<table_name>';
var parentRecord = '<table_sys_id>';

var ecc = new GlideRecord('ecc_queue');
ecc.agent = 'AttachmentCreator';
ecc.topic = 'AttachmentCreator';
ecc.source = parentTable + ':' + parentRecord;
ecc.name = '<file_name>:<mime_type>';
ecc.payload = '<base_64_encoded_file_content>';
ecc.insert();

  

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron

@rohit_hatkar1 

ServiceNow OOTB Attachment API doesn't support multiple files

You can create Scripted REST API and ask 3rd party to send array of JSON object and then handle it using customization.

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi  @Ankur Bawiskar ,

Thank you for the response. I am trying to create the attachment using the AttachmentCreator in the ecc queu. Using the below code create an attachment but the problem is for docs and excel it is not working. 

 

var parentTable = '<table_name>';
var parentRecord = '<table_sys_id>';

var ecc = new GlideRecord('ecc_queue');
ecc.agent = 'AttachmentCreator';
ecc.topic = 'AttachmentCreator';
ecc.source = parentTable + ':' + parentRecord;
ecc.name = '<file_name>:<mime_type>';
ecc.payload = '<base_64_encoded_file_content>';
ecc.insert();

  

@rohit_hatkar1 

it should work file provided you are giving correct file type and base64 encoded data

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Can you please help me with the <MIM Type> for excel and doc. currently I am passing 

'application/vnd.openxmlformats-officedocument.wordprocessingml.document'