I found the code below which does work except for segments after the FT1 segments. At the bottom of my message is a GT1, IN1 and IN2 Segment. There are 9 FT1 segments and the GT1, IN1 and IN2 only show up on the last message.
// Get headers to use on all new messages
var headers = message.getNode('MSH[group=!FT1]');
//Retrieve the FT1 Segments
var ft1Groups = message.getAllNodes('FT1[group=!FT1]');
//Loop Through Each one
for (var i=0 ; i < ft1Groups.length ; i++) {
//Set newMessage to the headers and the individual FT1 Segment
var newMessage = qie.parseHL7String(headers + ft1Groups[i]);
//Reset FT1-1 to "1"
newMessage.setNode('FT1-1', '1');
// Ensure we have a unique id in MSH-10 (message ID)
// so the messages don't error out in the receiving system
newMessage.setNode('MSH-10', newMessage.getNode('MSH-10') + '-' + i);
// Send the new message through to the remaining nodes
qie.spawnNewMessage(newMessage);
}
//Discard original message as it is no longer needed.
message.discard();