- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 07:17 AM
Hi,
CSV files are created when a certain event happens. The CSV files are created within a business rule ans should be sent to the MID server in order to forwarded to another server via SCP. What's the best way to send the CSV files to the MID server?
thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2024 08:34 AM
I think this script should help you. It should create a CSV file (just edit the text variable with the content from your CSV file) and using ecc_agent_attachment and ecc_queue tables it will save that file in the /agent/export folder of your ServiceNow installation on the MID Server.
var d = new Date();
var filename = 'DummyFilename_' + d.getTime().toString() + '.csv';
var text = 'Column_1;Column_2;Column_3\n';
text += 'Lorem;ipsum;dolor\n';
text += 'sit;amet;consectetur';
var midServerAttachGR = new GlideRecord('ecc_agent_attachment');
midServerAttachGR.initialize();
midServerAttachGR.name = filename;
midServerAttachGR.short_description = filename;
var new_table_sys_id = midServerAttachGR.insert();
//Create file
var sa = new Attachment();
var attachmentId = sa.write('ecc_agent_attachment', new_table_sys_id, filename, 'text/csv', text);
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', new_table_sys_id);
gr.query();
if (gr.next()) {
var ecc_queue = new GlideRecord("ecc_queue");
ecc_queue.initialize();
ecc_queue.agent = "mid.server.XXXXX"; //Put here your MID Server agent service name
ecc_queue.name = filename;
ecc_queue.queue = "output";
ecc_queue.topic = "StreamPipeline";
var xml = '<?xml version="1.0" encoding="UTF-8"?>';
xml += '<parameters>';
xml += '<parameter name="stream_relay_response_topic" value="ExportSetResult"/>';
xml += '<stream_relay_source attachment_sys_id="' + gr.sys_id + '" type="AttachmentSource"/>';
xml += '<stream_relay_transform attachment.table_sys_id="' + gr.table_sys_id + '" order="0" stream_relay_transfer_progress_interval="150" type="AttachmentProgressTransformer"/>';
xml += '<stream_relay_sink path="/' + filename + '" type="FileSink"/>';
xml += '</parameters>';
ecc_queue.payload = xml;
//Get SysID of new ECC Queue record
var ecc_sysid = ecc_queue.insert();
}
Hope this helps.
Regards,
Simone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 08:58 AM
You could try setting up an Export Set: https://www.youtube.com/watch?v=XV_C5OrHzrk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 09:06 AM
I had a look at export sets but that won't work since there is a fair amount of logic that needs to occur for putting the CSV files together.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 12:40 AM
I had a look at Export sets and they would work if the data that goes into my CSV files would come from a table. In my case, there is some logic which has been implemented in the business rule to create or adapt the data in the CSV files.
Any other possible solutions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 02:01 AM
Any suggestion?