- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2020 01:39 PM
Hi,
I would like to have the general overview / method as to how I can import data from a txt file and insert it into a table.
The client will drag and drop the txt file into an import table, then will click on UI action that will start the import.
A helpful answer would specify if there is a need for an intermiediate table, and how to insert the data into the target table.
An example would be very helpful.
This is what the txt file looks like:
NAME;FIRSTNAME;IDENTIFIANT;CURRENT_STATUS
JEAN;SYLVIE;A80625;ACT
PAUL;DANIEL;T80409;ACT
LEA;FRANCOIS;H0P437;ACT
Thank you,
OH
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2020 02:28 PM
Hi,
Yes you can read the content of the attachment and use it in the record. Please find the below link of a Article by Abhishek.
var tableName = 'incident';
var sysIdOfRecord = 'b98d17f11ba73300364d32a3cc4bcb29';
var fileNameWithoutExtension = 'Demo'; //Full file name: example text doc.txt
var grWithAttachment = new GlideRecord(tableName);
grWithAttachment.get(sysIdOfRecord);
var gsa = new GlideSysAttachment();
//ONLY works in global
var dataInTextFile = gsa.get(grWithAttachment, fileNameWithoutExtension);
Above piece of script from Article would be useful for you in reading the content on the attachment.
you can write a code in your ui action to read an attachment on the record and using glide record you could insert/update a record on other table.
Kindly mark my answer as Correct and Helpful based on the impact.
Regards,
Chaitanya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2020 02:35 PM
I see the link you posted has code that uses a Packages call. I thought they restricted packages calls some time ago, I guess not.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 11:07 AM
Yeah! Before posting the answer even I was not sure so I tried the code in background script in my PDI, and The attachment content was successfully retrieved.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2020 02:29 PM
You are going to have to use an import set to do this. But what you are doing is similar to this
https://community.servicenow.com/community?id=community_blog&sys_id=908c26e1dbd0dbc01dcaf3231f9619c4
So once they attach the file and hit the button you can copy the attachment over over to a data source and use the above to run it.