Sidebar

How do I create 2 output messages?

0 votes
460 views
asked Jun 3, 2015 by torin-s-1331 (120 points)
Is it possible to generate 2 output files as a result of mapping nodes that do processing for a channel?

var message1 = qie.createXMLMessage('<RootNode></RootNode>')

mulitple calls to message1.addChildMessage('/RootNode', someElement);

var message2 = qie.createCSVMessage();

message2.setNode.('*[1]','\"FieldName\"');

for (var i=1; i<=myList.getRowCount(); i++) {

    var fieldName = myList.getNode('FieldName', i);

    message2.setNode('FieldName', fieldName, i+1; true);

}

// Now that I have message1 and message2, what do I need to do to get them both written to files?

// I want message1 written to file1.xml and message2 written to file2.csv.

// Is this possible?  Do I need multiple destination nodes?

1 Answer

+1 vote

Good question.  I would use qie.writeFile() like this:

var destinationPath = "C:" + File.separator + "Some" + File.separator + "Location";
var fileName = "file_name";
 
qie.writeFile(destinationPath + File.separator + fileName + '.xml', message1.getNode('/'), false);
qie.writeFile(destinationPath + File.separator + fileName + '.csv', message2.getNode('/'), false);
The Code Wizard has a description of the qie.writeFile() function.  This approach will overwrite the existing file at that path.  (You could do some name conflict resolution if you needed to.)
 
Alternatively, yes.  You could route to multiple mapping nodes, and set the message object for both, and then route to separate destination nodes.  One advantage of using a destination node is it will handle resolving naming conflicts for you.
answered Jun 3, 2015 by mike-r-7535 (13,830 points)
...