- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 01:34 PM
I have a MID Server set up and successfully using it for exports from ServiceNow. Now, I want to import CSV files via the MID Server, but I don't see it listed as an option under Data Sources > File Retrieval Methods.
Is it possible to import CSV files through a MID Server? If so, how can this be achieved?
If MID Server is not an option, what are my alternatives for importing CSV files?
If I use SFTP as a retrieval method, would I need to whitelist the ServiceNow instance’s IP address on the SFTP server?
Any guidance or best practices would be greatly appreciated!
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 02:33 PM
Hi @SwathiBanda,
You can try executing a PowerShell script (Which should be stored on your MID server). This script should then execute the attachment API to upload the file into a given data source.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0817437
You can build a Flow action which can be given the PowerShell script path as an input and use a script action like:
(function execute(inputs, outputs) {
//Get the name of an Active Mid Server
var midName = "";
var eccObj = new GlideRecord("ecc_agent_capability_m2m");
eccObj.addEncodedQuery("capability.capabilityINPowerShell,ALL");
eccObj.addQuery("agent.status", "Up");
eccObj.query();
if(eccObj.next()){
midName = "mid.server." + eccObj.agent.name;
}
var filePath = inputs.filePath;
//Create Output ecc record to execute the powershell file in MID server
var ecc = new GlideRecord("ecc_queue");
ecc.initialize();
ecc.agent = midName;
ecc.topic = "Command";
ecc.name = "powershell " + filePath;
ecc.queue = "output";
ecc.state = "ready";
ecc.source = "PowerShell";
ecc.payload = '<?xml version="1.0" encoding="UTF-8"?><parameters><parameter name="skip_sensor" value="true"/></parameters>';
ecc.insert();
})(inputs, outputs);
For the PowerShell script you can check the one in this post and adjust it as per your requirement:
https://www.servicenow.com/community/developer-forum/powershell-rest-attachment-api-looking-for-work...
You would need to create a user account with the necessary accesses for the integration.
How this works, a scheduled flow is running and executing the action. The action would then run the command to execute the PowerShell Script on the MID server. The PowerShell script would then use the service account to upload the file from the MID server using the OOTB attachment API as a REST Call.
We have this up and running without an issue!
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 02:33 PM
Hi @SwathiBanda,
You can try executing a PowerShell script (Which should be stored on your MID server). This script should then execute the attachment API to upload the file into a given data source.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0817437
You can build a Flow action which can be given the PowerShell script path as an input and use a script action like:
(function execute(inputs, outputs) {
//Get the name of an Active Mid Server
var midName = "";
var eccObj = new GlideRecord("ecc_agent_capability_m2m");
eccObj.addEncodedQuery("capability.capabilityINPowerShell,ALL");
eccObj.addQuery("agent.status", "Up");
eccObj.query();
if(eccObj.next()){
midName = "mid.server." + eccObj.agent.name;
}
var filePath = inputs.filePath;
//Create Output ecc record to execute the powershell file in MID server
var ecc = new GlideRecord("ecc_queue");
ecc.initialize();
ecc.agent = midName;
ecc.topic = "Command";
ecc.name = "powershell " + filePath;
ecc.queue = "output";
ecc.state = "ready";
ecc.source = "PowerShell";
ecc.payload = '<?xml version="1.0" encoding="UTF-8"?><parameters><parameter name="skip_sensor" value="true"/></parameters>';
ecc.insert();
})(inputs, outputs);
For the PowerShell script you can check the one in this post and adjust it as per your requirement:
https://www.servicenow.com/community/developer-forum/powershell-rest-attachment-api-looking-for-work...
You would need to create a user account with the necessary accesses for the integration.
How this works, a scheduled flow is running and executing the action. The action would then run the command to execute the PowerShell Script on the MID server. The PowerShell script would then use the service account to upload the file from the MID server using the OOTB attachment API as a REST Call.
We have this up and running without an issue!
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.