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

Prasant Kumar 1
Kilo Sage

Hi,

Please follow the below links:-

https://docs.servicenow.com/bundle/orlando-platform-administration/page/administer/import-sets/conce...

 

https://www.youtube.com/watch?v=6yGke5WSf9A

 

If i was able to solve your query, Please mark my answer correct and helpful.

Thanks & Regards

Prasant kumar sahu

 

Sukraj Raikhraj
Kilo Sage

using the load data and import set feature in SN, the data can be loaded and transform to target table. The only issue is that I don't think that ; is an acceptable delimiter symbol ( pipe, comma and tabs are currently supported).

Can we do the import without going through an import set. That's the whole reason I asked the question.

Thanks

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