- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2025 12:15 AM
Hello SN community.
I have a batch of records that have attached a file that comes from another integration. I have a task where I require to locate the attached file and read it. Can you please provide with some guidance on how I can do that?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2025 02:28 AM
Hello @fahabil698 !
Assuming the attachments are of type .json, .txt, etc., here is a sample script you can use and adapt to your needs to read the contents of the attachment:
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addQuery('table_name', '<your_table_name>');
grAttachment.addQuery('table_sys_id', '<your_record_sys_id>');
grAttachment.query();
if (grAttachment.next()) {
var inputStream = new GlideSysAttachment().getContentStream(grAttachment.getUniqueValue());
if (inputStream) {
var reader = new GlideTextReader(inputStream);
var line = '';
var fileContent = '';
while ((line = reader.readLine()) !== null) {
fileContent += line;
}
gs.info(fileContent);
}
}
Please consider marking my answer as helpful and accepting it as the solution if it assisted you in any way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2025 02:44 AM
hi @fahabil698,
all the attachments are located at the table [sys_attachment], usually their ale linked via sys ID to particular records (incidents, ritms, etc.) - so if you have INC0001 get its sys id and search for it in the Attachment table.
Let me know if it answers your question or need more details
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */