Convert attached PDF to text
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 05:16 PM
Hey all,
I want to parse data which is attached to record/incident and get that data into Text format. Does anyone know how can I achieve it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 08:37 PM
Hi @shan82 ,
Following is the example to convert data to plain text:
You can create a Business Rule that runs when a new Knowledge Article is created through the Record Producer. The Business Rule can then extract the content of the Word document attachment and populate the 'text' field of the Knowledge Article with this content.
Here are the steps to create the Business Rule:
- Navigate to System Definition > Business Rules and click on 'New'.
- Set the Name of the Business Rule to something like 'Import Word Document to Knowledge Article'.
- Set the Table to 'KB_Knowledge'.//change to your table
- Set the When to 'Before Insert'.
- In the Advanced field, enter the following script:
(function executeRule(current, previous /*null when async*/) { //if (current.<custom_field> == 'record_producer') {} /* you can set this condition to identify this particluar kb article has been created record producer, you can set any unused field or create custom field and set value in record producer */ // Get the attachment object from the Knowledge Article record var grAttachment = new GlideRecord('sys_attachment'); grAttachment.addQuery('table_sys_id', current.sys_id); grAttachment.query(); // Check if an attachment record exists if (grAttachment.next()) { // Get the attachment file object and read the file content var attachment = new sn_impex.GlideExcelParser(); var attachmentSysId = grAttachment.getUniqueValue(); var fileContent = attachment.parseExcel(attachmentSysId).toPlainText(); // Set the text field of the Knowledge Article to the file content current.text = fileContent; } })(current, previous);
6. Click on 'Save' to save the Business Rule.
Refer to following thread:
https://www.workingcode.in/question/convert-text-into-pdf-attachment-servicenow/
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 12:02 PM
Hello Sumanth,
Will this work for PDF as well? my attachment is PDF, not a word document.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
I had a similar case and used a Flow to grab the PDF attachment, then passed it through OCR using a Script step. If the PDF has actual text, you can extract it directly, but scanned docs need image to text conversion first with OCR. Then I used the result to fill in fields on the record.