How can i read a csv file that is in a midserver folder via script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2025 09:49 AM
Hello,
I need to create a script so that daily I read a csv file that another application is creating inside a folder on my midserver every day.
Can someone give me an example of how I can read this file via script and parse this csv?
exempla of csv file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2025 09:54 AM
This is not a recommended solution to import CSV from MID Server to Instance.
There are options available. Refer "Attaching Files Directly using the Attachment API or MID Command Probes" from the below article:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0817437
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2025 10:18 AM
Hello @bgmoreira
You can’t read a file directly from the MID Server folder with just a script in ServiceNow, because the instance has no direct access to the MID Server operating system.
The supported pattern is:
The external system drops the CSV into a known folder on the MID.
From ServiceNow, you trigger a probe or script through the ECC Queue to ask the MID to read the file.
The MID reads the file and sends the content back to the instance via ECC Queue.
Once you have the file content in the instance, you parse it with the sn_impex.CSVParser API.
Example of parsing once you already have the CSV content in a string:
var csv = "name,age,city\nJohn,30,NY\nJane,25,LA"; // file content received
var parser = new sn_impex.CSVParser();
var data = parser.parse(csv);
for (var i = 0; i < data.size(); i++) {
var row = data.get(i);
gs.info("Name: " + row.get("name") + " | Age: " + row.get("age") + " | City: " + row.get("city"));
}
To automate daily, you would:
Create a Scheduled Job to trigger the probe.
The probe reads the file on the MID.
The content comes back via ECC Queue.
Your script parses and loads the data into the target table.
This is the recommended flow: Instance ? MID Probe ? ECC Queue ? Parse in ServiceNow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2025 11:05 AM
Seems to be a question on a script to run on a Linux or Windows environment, to parse a csv file there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2025 11:22 AM
You can use PowerShell commands on Windows. Refer the below URL:
Palani
