No announcement yet.

ForEach Java Loop

  • Filter
  • Time
  • Show
Clear All
new posts

  • ForEach Java Loop

    Hey Everyone,

    I am sure this is a simple fix but I am kinda new to Javascript and trying to fix a problem I've been given.

    Basically I have an incoming interface that gives me a dynamic number of OBX segments. Could be two or three or four. What I'm trying to do is take the data from OBX 5.1 and move that to OBX 5.5 while appending it with ^AP^PDF^Base64^.

    In summary:
    1 OBX 5.1 'random encoded data' -> OBX5.1 'AP'PDF'Base64'random encoded data'
    2 OBX 5.1 'random encoded data' -> OBX5.1 'AP'PDF'Base64'random encoded data'
    3 OBX 5.1 'random encoded data' -> OBX5.1 'AP'PDF'Base64'random encoded data'

    Hope I'm explaining myself correctly but I've been looking at it for a half day and have no idea why it's not working.

  • #2
    are you getting an error? can you post what you have already done?


    Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

    Appliance Version 3.11.4
    Mirth Connect Version 3.8.0
    Java Version 1.6.0_45-b06
    Java (64 bit) Version 1.6.0_45-b06
    Java 7 (64 bit) Version 1.7.0_151-b15
    Java 8 (64 bit) Version 1.8.0_181-b13
    PostgreSQL Version 9.6.8


    • #3
      obx_count = 0;

      for each(obx in msg['OBX'])
      msg['OBX'][obx_count]['OBX.5] = msg['OBX'][obx_count++]['OBX.1'].toString() + '^AP^PDF^Base64^';


      • #4
        I think this is what you were trying to say. You have to remember when you are in a transformer that you're working with xml objects, not strings. Your field and component separators are not part of your data.

        for each (var obx5 in msg.OBX['OBX.5']) {
            obx5['OBX.5.2'] = 'AP';
            obx5['OBX.5.3'] = 'PDF';
            obx5['OBX.5.4'] = 'Base64';
            obx5['OBX.5.5'] = obx5['OBX.5.1'].toString();
        It is a good idea when you post to include your code that isn't working, like Kirby said. It helps other people help you to understand what you are doing wrong.
        Last edited by agermano; 12-18-2019, 08:22 AM.