No announcement yet.

Accepting wanted segments instead of deleting the unwanted ones.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Accepting wanted segments instead of deleting the unwanted ones.

    Currently my transformer deletes a list of unwanted segments.
    delete msg['ZIR'];
    delete msg['ZEN'];
    delete msg['ZSP'];
    Is there a way to keep only the segments that I need without using the static delete so that changes in the source message such as adding another z or IN segment do not affect the channel?

    Something along the lines of:

    If segment is not MSH, PID PV1 then delete segment.

  • #2
    for each (seg in msg)
    segName =;
    if(segName != 'PID' && segName != 'MSH' && segName != 'PV1')
    delete seg;


    • #3
      If you have a large set of segments you want to keep you could do this:

      var strGoodSeg = 'MSH~PID~PV1~NK1~OBR'  //you get the point right?
      for each (seg in msg.children()) {
         var strCurSeg =;
         if (strGoodSeg.indexOf(strCurSeg) < 0) {     //okay to delete
               delete seg;
      I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com

      Test all my code suggestions prior to implementation


      • #4
        Apologies for revitalizing this old thread but I find myself in a similar situation.
        I also would like to only keep MSH, PID, NTE, and delete everything else. I tried the code above by Cory Cole and Bostad and it is not working for me.
        The delete msg['IN1'] for example works fine but like the author, I want something more robust than the static delete function.
        I have tried the code as javascript in both source and destination transformer.
        When I send a test message the entire message passes through as if the javascript was not there. (Yes the transformer is checked).

        I am on version 3.8.0
        Appreciate any tips.
        Thank you


        • #5
          Here's a different way to do it.

          const segmentsToKeep = new java.util.HashSet(['MSH','PID','NTE']);
          var newChildren = new XMLList();
          for each (var seg in msg.children()) {
              if (segmentsToKeep.contains(seg.localName())) newChildren += seg;


          • #6
            Thank you this one works.