How to send attachments and data to AZURE AI

Akash_16
Tera Contributor

Hi All,
There is one requirements where we need to send the attachments which is present in the incident.


There is already an implementation on sending the incident information to the azure ai, The AI summarize the content based on the incident data which we are passing which is working fine.


Now, We need to send attachments which is attached to the incident (like pdf,doc,image etc) and along with incident data to azure ai, Now AI has to summarize the content based on the attachments and also with the incident data.

4 REPLIES 4

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Akash_16 

Below Code is from Dev Instance that help!!

Attachments in ServiceNow are stored in the sys_attachment table, with file content in sys_attachment_doc.

To get all attachments for a given Incident:

 

 
var attachmentIds = [];
var grAttach = new GlideRecord('sys_attachment');
grAttach.addQuery('table_sys_id', incidentSysId);
grAttach.addQuery('table_name', 'incident');
grAttach.query();
while (grAttach.next()) {
attachmentIds.push(grAttach.sys_id.toString());
}

 

2. Convert attachments into a usable format

The content itself is stored as chunks in sys_attachment_doc. You’ll need to stream/encode these for sending to Azure.

Simplified function to get the base64 file content:

 

 
function getAttachmentBase64(attachmentSysId) {
var gsa = new GlideSysAttachment();
return gsa.getBytes(attachmentSysId); // returns byte[]; encode as base64
}

 

If you’re using RESTMessageV2 to call Azure, you’ll want to base64-encode:

var gsa = new GlideSysAttachment();
var bytes = gsa.getBytes(attachSysId);
var base64Content = GlideStringUtil.base64Encode(bytes);

 

3. Build the payload for Azure AI

You have two options here:

  • Option A: Send as inline base64 data (for small/moderate files).

  • Option B: Upload to blob storage (Azure Storage), then send the file URLs to the AI service along with incident text. This is cleaner if files are large.

Example payload (inline base64):

 

 
{ "incident": { "number": "INC0012345", "short_description": "User unable to login", "description": "The user reports SSO failure..." }, "attachments": [ { "name": "error_screenshot.png", "content_type": "image/png", "data": "<base64 string here>" }, { "name": "logfile.pdf", "content_type": "application/pdf", "data": "<base64 string here>" } ] }

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

@Akash_16 

Could you please help sharing if the JSON request body is supported by Azure AI API?

Also could you please help sharing the documentation link so that it helps members to understand from where this was referred?

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Akash_16 

you first need to understand what Azure API supports in terms of accepting attachment.

Did you check their API documentation?

what HTTP method they accept, what request body looks like?

Once you know these details you can then write the script in ServiceNow.

I found this, please check

Azure AI services REST API reference 

also this

Upload File - Part 

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

@Akash_16 

Hope you are doing good.

Did my reply answer your question?

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