Create Text file and send to MID Server in ServiceNow
ServiceNow Export Set offers to export data in a limited format, as shown below. This article will discuss how to create a .txt file and export it to MID Server.
Below is how to consume the Script Include/* esline no-undef:error,no-unused-vars:warning */var FileTransferUtil = Class.create();FileTransferUtil.prototype = {initialize: function() {},CreateTextFile: function() {var fileContent = "This is a sample text file";fileName = 'CustomeText.txt';var eccAttachment = new GlideRecord('ecc_agent_attachment');eccAttachment.initialize();eccAttachment.name = 'Export Set Attachment';eccAttachment.short_description = 'Exporting Custom Text File:' + fileName;var eccAtt_sys_id = eccAttachment.insert();var attachment = new GlideSysAttachment();var attachmentRec = attachment.write(eccAttachment, fileName, "text", fileContent);if (!gs.nil(attachmentRec)) {var xmlString = '<?xml version="1.0" encoding="UTF-8"?>' +'<parameters>' +'<parameter name=\"stream_relay_response_topic\" value=\"ExportSetResult\"/>' +'<stream_relay_source attachment_sys_id=\"' + attachmentRec + '\" type=\"AttachmentSource\"/>' +'<stream_relay_transform attachment.table_sys_id=\"' + eccAtt_sys_id + '\" order=\"0\" stream_relay_transfer_progress_interval=\"150\" type=\"AttachmentProgressTransformer\"/>' +'<stream_relay_sink path="\/' + fileName + '\" type=\"FileSink\"/>' +'</parameters>';//stream_relay_sink path update as per requirement// agent/export/ is base folder// Create ECC Recordvar eccQueue = new GlideRecord('ecc_queue');eccQueue.initialize();eccQueue.agent = 'mid.server.XXXXXXXXX';//MID Server NameeccQueue.topic = 'StreamPipeline';eccQueue.queue = 'output';eccQueue.state = 'ready';eccQueue.payload = xmlString;eccQueue.insert();}},type: 'FileTransferUtil'};