I was talking to Nthumma about a problem. It was the need for a custom XML file for each incident. I knew of a way to do this, but it’s old. Enter Processors.

So if you ever have a need to make something auto-download, that would seem pretty difficult as you need to set headers as mentioned here on stackoverlow.

However, with processors this is a non-issue. Here’s how to do it.

// Processor code
(function process(g_request, g_response, g_processor) {
try{
var filter = g_request.getParameter("filterQuery");
var fileName = filter + '.xml';
var contentType = 'xml/plain';
var fileContent = '';
var incident = new GlideRecord('incident');
incident.query();
fileContent+='<root>';
while(incident.next()) {
//generate XML format
fileContent+='<record>';
fileContent+='<message-type>'+ incident.getValue('short_description')+'</message-type>';
fileContent+='</record>';
}
fileContent+='</root>';
if(contentType == 'xml/plain'){
fileContent = new XMLDocument(fileContent);
}
g_processor.writeOutput(contentType,fileContent);
} catch(error){
g_processor.writeOutput('text/html',error);
}
})(g_request, g_response, g_processor);


UI Action

// Client side ui action