How to read content of a DOC file

Shubhanshu Guh1
Giga Contributor

Hi,
Our need is to read content present in a Word attachment attached to a record and update the 'Comment' field with the content present in the Word attachment. The attachment may include images, the 'Comment' field is a HTML type field.

If this requirement has been done before, do share your views.

Used code to read values : https://gist.github.com/pmgupte/df835d6cdacf0345c2bc, but the variable returns 'unidentified'.

Thanks in advance!

1 ACCEPTED SOLUTION

check these links for alternative solution

Apache POI - the Java API for Microsoft Documents

How to parse an MS word document attachment into text - Developer Community - Question - ServiceNow ...

Regards
Ankur

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

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

so can you share what script you tried; what debugging you performed?

regards
Ankur

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

var gr = new GlideRecord("table_name_here");
gr.addActiveQuery();
gr.query();
//gs.print('1 ' + gr.getClassDisplayValue());
while (gr.next()) {

var grAttch = new GlideRecord('sys_attachment');

grAttch.addQuery('table_sys_id', gr.sys_id); // get attcahments for current incident
grAttch.query();
if (grAttch.getRowCount() > 0) { //attachment exist
while (grAttch.next()) {
var sa = new GlideSysAttachment();
var dataInTextFile = sa.get(grAttch, 'attachment_name_here');
gs.print("Information Available in Text File: " + dataInTextFile);
var attachmentContents = sa.getContent(grAttch);
gs.print('Attach Content : ' + attachmentContents);

}
}
}

Hi,

doc files are not simple text or csv file which can be read with getContent()

Regards
Ankur

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

check these links for alternative solution

Apache POI - the Java API for Microsoft Documents

How to parse an MS word document attachment into text - Developer Community - Question - ServiceNow ...

Regards
Ankur

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