Attachment insertion through import set api in ServiceNow

Kishor O
Tera Sage

I have a string field u_attachment in an import set table in ServiceNow. I want to use this field to create an attachment via the Import Set API. What should the request body look like, and what details are required to successfully create the attachment?

 

Thanks!

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Kishor O 

You will require these details in the import set API so that on target record you can attach file

Something like this in import set table and then you can grab the details and use GlideSysAttachment API or AttachmentCreator to load file.

Below fields will be required from 3rd party in import set

{
"incidentNumber": "INC000124",
"fileName": "my file.txt",
"contentType": "text/plain",
"fileData": "base64EncodedData"
}

I shared solution for something similar here, please enhance, it was for scripted REST API. you can enhance the logic in onBefore or onAfter transform script

Scripted Rest API to update incident with attachment 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar  Would it be feasible to store all the attachment-related data in a JSON string and process it accordingly? This approach should ideally support multiple attachments in a single operation

@Kishor O 

If 3rd party sends array of JSON object containing attachment data in single row then you can use the above logic and use onBefore or onAfter transfrom script to load that file in target record

how does the JSON from 3rd party look like?

You can always discuss with 3rd party and agree on format.

If you use Scripted REST API it gives you more control over the JSON request body and you can ask 3rd party to send format in what you require which makes your job as developer in ServiceNow easy.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Kishor O 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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