Mirth Connect 4.1.0 Released!

Mirth Connect 4.1.0 is now available as an appliance update and on our GitHub page. Mirth Connect 4.1.0 includes new features such as new event log messages, additional fields to the Welcome to Mirth Connect screen, new information included in alerts as well as many smaller changes, updates, and improvements. This release also contains several improvements to commercial extensions. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

Trying to Delete all repeating segments of AIP except for the first one.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Trying to Delete all repeating segments of AIP except for the first one.

    Hello all,

    We are using Mirth version 3.11.0.

    I'm pretty new to Mirth and am trying to utilize a prior co-worker's Javascript code on a new outbound channel. The receiving entity only wants the first AIP segment with the attending provider. When I use the script, it deletes the second instance of AIP, but not third or more. I assume it is failing to iterate to the next loop, but I don't understand why.

    Here is the code I am using.

    var aipcount = 0;
    for each (aip in msg['AIP']) {
    if (aipcount != 0)
    delete msg['AIP'][aipcount];

    Any help would be appreciated!

    Thanks, Mayo

  • #2
    Might be useful for you to read

    The pertient part is what actually happens to the XML behind the scenes when you call delete on a segment.
    Diridium Technologies, Inc.


    • #3
      Ok, thank you for leading me to that discussion. Here is the solution I have arrived at and it appears to be doing what I want. Do you see any issues with it?

      for (var i = msg['AIP'].length(); i >= 1; i--) {
          if (msg['AIP'][i] != 0) {
          delete msg['AIP'][i];


      • #4
        Be mindful you can just change the for loop to stop sooner, i.e. before it hits the first AIP. You don't need the if statement then.
        Diridium Technologies, Inc.