How to import data from a txt file

hamidouche
Kilo Expert

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

1 ACCEPTED SOLUTION

Chaitanya Redd5
Tera Guru

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.

https://community.servicenow.com/community?id=community_article&sys_id=9ed305e2db63fb845129a851ca961...

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

View solution in original post

7 REPLIES 7

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.

 

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.

DrewW
Mega Sage
Mega Sage

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.