Importing a csv file without column headers

Joey Wan Kenobi
Tera Guru

Is this possible?

8 REPLIES 8

We have to communicate with some "ugly" system which is providing data without header.



As I mentioned I would like to save the data from every row into single column and then parse the column based on some rules.


Very dirty approach, but seems as the only way.


faro
Tera Expert

workaround I've used > get the data into Excel (or equivalent spreadsheet), then add header, save, etc..


But I am exploring using a script to do this.


Hadyn
Tera Expert

I just had the same need. My data source comes from a csv hosted on a web server so I use the HTTPS method. What I did was created a custom processor on my instance ie https://blah.service-now.com/mycsv. In the processor I use REST api to get my original csv and then I add a header row to it and serve it back to the requestor (data source).

This is my processor script: 

(function process(g_request, g_response, g_processor) {
	var sm = new sn_ws.RESTMessageV2();
	sm.setEndpoint("http://originalsourceofcsv.com.au/thecsv");
	sm.setHttpMethod("get");
	sm.setHttpTimeout(6000);  //optional
	sm.setLogLevel("all");  //optional
	sm.setMIDServer("Mid1"); //optional
	var response = sm.execute(); 
	
	//Write output
	var headerrow = "Column1,Column2,Column3,Column4\n";	
	g_processor.writeOutput("text/plain",headerrow + response.getBody());
})(g_request, g_response, g_processor);

kkaufmann
Tera Contributor

Hadyn,

I think this will work for an issue I am currently having where I have a duplicate column in a CSV file I get daily from an FTP server.  However, I'm not sure what you mean by "serve it back to the requestor (data source)." How would I get the newly edited file into data source?

Thanks!