Need to auto parse the text file

SagarGadakh
Tera Contributor

Hello,

There is a record which is created in a table which has a text file attachment. Need to auto parse the text file and need to create the records in another table for the attached file.

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@SagarGadakh 

you can use GlideSysAttachment API to reach txt file

but text file is not something which can be relied to create records into other file

is this a learning exercise or a business requirement?

script like this

var   gr = new GlideRecord('sys_attachment');
gr.addQuery('sys_id', 'e9f5dcbb4f103200fc11fa218110c77c'); // sys_id of attachment record
gr.query();
if(gr.next()){
var gsa = new GlideSysAttachment();
var bytesInFile = gsa.getBytes('u_sample_table', gr.table_sys_id);
var dataAsString = Packages.java.lang.String(bytesInFile);
dataAsString = String(dataAsString);
gs.print(dataAsString);
}

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

@SagarGadakh 

Hope you are doing good.

Did my reply answer your question?

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

Mark Manders
Mega Patron

Share has a custom action for inbound emails. You could check if you can adjust it to be used on the file:

https://developer.servicenow.com/connect.do#!/share/contents/8408077_parse_email_flow_action?v=2.4&t...


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

woodyfairley
Tera Guru

I did this by converting the text file into a CSV file, then creating an import set table with a predefined field map, attaching the CSV to the import set. Then I scheduled the import, making a log entry containing success or error codes then delete the imported CSV file.

 

Pseudocode:

PRE-REQUISITE ACTIONS

1 create import set table

2 create import set

3 create import schedule

SCRIPT

1 check for new record with attachment

2 if found then convert text file into CSV file

3 attach new CSV file to import set

IMPORT SET SCHEDULE

1 trigger on a schedule

2 import CSV using pre-defined import set field mapping

3 create log entry with success or error codes

4 if success then delete CSV file