Attachment Summarization with GenAI – Ready-to-Use Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi everyone!
If you're exploring ways to summarize attachments using ServiceNow's GenAI capabilities, here's a quick script that taps into the DocIntel GenAI plugin to process and summarize attachments linked to a specific record.
This script uses out-of-the-box Script Includes and currently supports PDF, Word, Excel, and image files.
Prerequisite: Make sure the Now Assist for Platform plugin is enabled and the "Extract information from documents" skill is activated in your instance. These are required to use the summarization APIs shown below.
(function() {
var attachmentIds = [];
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', 'sys_id here'); // Replace with your target record Sys ID
gr.query();
while (gr.next()) {
attachmentIds.push(gr.getUniqueValue());
}
var docintelGenAIConstants = new sn_docintel_gen_ai.DocintelGenAIConstants();
var attSumAPI = new sn_docintel_gen_ai.AttachmentSummarizer();
var taskDefinitionSysId = docintelGenAIConstants.ATTACHMENT_SUMMARIZATION_AGENT_TASK_DEF_ID;
var taskID = attSumAPI.processAttachmentSysIds(attachmentIds, taskDefinitionSysId);
var docintelAPI = new sn_docintel_gen_ai.DocintelGenAIQuery();
gs.sleep(5000); // Optional: wait for summarization to complete
var result = docintelAPI.getSingleResultForTask(taskID);
gs.log('result is ' + JSON.stringify(result));
})();
Script Includes Used: All are OOB (DocintelGenAIConstants, AttachmentSummarizer, DocintelGenAIQuery)
Supported File Types: PDF, Word, Excel, and image formats
Customization: You can replace the table_sys_id with any record you want to summarize attachments for.
- Async Execution: The summarization task runs asynchronously. I’ve used gs.sleep(5000) here just to simulate a delay before fetching the result. For production-grade implementations, consider using a more robust approach like polling with a scheduled job or callback mechanism to handle task completion gracefully.
