Search Content in Attachment in Attachment Table

Sharath807
Tera Contributor

Hi all, Is it possible to search the content in attachment. For example If I attach some txt file in incidnet form that particulat attachement will create record in attachment table. So If i search some keywords in that attachment in attachment table will it return that attachment record. Any help ?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Sharath807 

First of all you can only get content of attachment for simple file types such as csv, txt, json etc

You cannot print normal content from other file types such as PDF, PPT, WORD etc

So that's not possible.

here is sample script to print content of txt or csv or json file

Scoped app

AnkurBawiskar_0-1752130072320.png

Global scope

AnkurBawiskar_1-1752130126509.png

 

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

View solution in original post

3 REPLIES 3

Community Alums
Not applicable

hi @Sharath807 ,

By default, ServiceNow does not allow you to search inside the actual content of attachments like .txt, .pdf, or .doc files. When you attach a file to a record, ServiceNow creates a reference in the sys_attachment table, but the text inside those files isn’t indexed or searchable. This means that if you search for a keyword that only exists inside the attached file, the search won’t return the related attachment or the parent record — it only looks at the fields stored on the form itself, like short description or comments.

To make attachment content searchable, you typically need to enable AI Search with attachment indexing. This feature lets ServiceNow’s search engine scan inside common document types and include them in search results, but it usually requires extra configuration and a subscription. Alternatively, some teams build custom solutions that read the text content of attachments using the Attachment API and copy it into a field on the parent record, so that normal searches will find it.

If you need help deciding between these options or want to see an example of how to extract and store attachment text, let me know — I’d be happy to help!

@Community Alums  Hi thanks for reply.  Yes please can you help to extract content in attachment and store in parent or custom table and use normal search to find attachment using keywords.

Ankur Bawiskar
Tera Patron
Tera Patron

@Sharath807 

First of all you can only get content of attachment for simple file types such as csv, txt, json etc

You cannot print normal content from other file types such as PDF, PPT, WORD etc

So that's not possible.

here is sample script to print content of txt or csv or json file

Scoped app

AnkurBawiskar_0-1752130072320.png

Global scope

AnkurBawiskar_1-1752130126509.png

 

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