brian_degroot
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