Need to auto parse the text file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 06:21 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 06:47 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 08:09 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 06:47 AM
Share has a custom action for inbound emails. You could check if you can adjust it to be used on the file:
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 07:59 AM
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