File Import (CSV / XLS) file from Mid Server location

tkrishna29
Giga Guru

I see this question has been asked several times and I see a recommendation of using an app from ServiceNow guru / Servicenow share / crossfuze solution. Most of the recommendations were dated 2 years ago.

Anything changed in ServiceNow where it's straightforward to import data from Mid Server? Greatly appreciate if someone can give pointers on best approach to do it without much custom coding. 

Thank you,

Krishna

 

1 ACCEPTED SOLUTION

brian_degroot
ServiceNow Employee
ServiceNow Employee

Hi Krishna,

Instead of writing the files to the MID Server host, it will probably be easier to have your 3rd party application write the file directly to the instance.

 You can either send it as an import set to the instance with the following endpoint URL:

https://<instance>.service-now.com/sys_import.do?sysparm_import_set_tablename=<import_table_name>&sysparm_transform_after_load=true&uploadfile=<path>.csv

More information on this method can be found here:

Alternatively, you can have the file attached to an existing record, such as an incident, by using Attachment API

If that's not an option and you need to pull from the MID Server host, you can take advantage of the MID Server command probe. This allows you to run shell commands on the system. What this would look like is:

var probe = SncProbe.get("Command");
probe.setName("cd /Users/me/Desktop && cat example.csv | base64");
probe.create("<MID Server Name>");

The response to this will be a base64 encoded string of the file that will get written to ECC Queue in the response. You can then turn this into an attachment with a script on the instance

var encStr = '<long base64 encoded string>';
var stringUtil = GlideStringUtil;
var attachment = new Attachment();
attachment.write('<table>', '<record sys_id>', '<file name>', 'text/csv', stringUtil.base64DecodeAsBytes(encStr));

 

I'm sure there's a better approach than that, but hopefully that gives you some ideas to work with. Best of luck!

 

-Brian

View solution in original post

20 REPLIES 20

Heads up guys!

To whom it will be interesting: I resolved this strange issue I mentioned above.

B/c MID in PROD is in high sec zone, those API required to use a proxy to reach instance.

So the final code will be like this:

Invoke-WebRequest -Headers $headers -Method POST -Proxy $proxy -Uri $uri -InFile "$file_path" -UseBasicParsing

 

Hope it will help others 🙂