Announcement

Collapse
No announcement yet.

Blanking repeating segment's field based on conditions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Blanking repeating segment's field based on conditions

    Trying to blank out NTE.3.1 when the NTE.2 field contains "X" and the MSH.9 is ORM.

    We can receive multiple NTEs so I have to use the iterate function. I'm not sure if I'm failing on that part of it, or in my final statement where I want to set the NTE.3 to be blank. The error I keep receiving seems like it leans that way. It reads:

    Code:
    TypeError: cannot set property "NTE.3.1" of undefined to ""
    Here is my code. I've tried removing the FOR statement, and the messages goes through without erroring OR blanking the NTE. When I keep the FOR statement, it errors. Not sure what I have to change. Do I have to split up the MSH criteria & repeating NTE criteria somehow?


    Code:
    for (var i = 0; i < msg['OBX'].length(); i++);
    
    {if (msg['MSH']['MSH.9']['MSH.9.1'].toString == 'ADT' && msg['NTE']['NTE.2'][i]['NTE.2.1'].toString() == 'X');
    
     
    //only if above criteria is met, the following will be performed:
    
    
    {
    msg['NTE']['NTE.3'][i]['NTE.3.1'] = "";
    
    }}

  • #2
    Code:
    if (msg['MSH']['MSH.9']['MSH.9.1'].toString == 'ADT')  {
         for each(nte in msg.NTE)  {
              if (nte['NTE.2']['NTE.2.1'].toString() == 'X')     {
    
    nte['NTE.3']['NTE.3.1'] = "";
    
    }
    }
    }
    Last edited by stormcel; 11-26-2019, 11:42 AM.

    Comment


    • #3
      Originally posted by stormcel View Post
      Code:
      if (msg['MSH']['MSH.9']['MSH.9.1'].toString == 'ADT')  {
           for each(nte in msg.NTE)  {
                if (nte['NTE.2']['NTE.2.1'].toString() == 'X')     {
      
      nte['NTE.3']['NTE.3.1'] = "";
      
      }
      Thank you. I put that in and had to add a couple braces } in the end, but once the transformer validated it did not blank out the field upon testing. This is v3.7.1 if it matters?

      Comment


      • #4
        well, I didn't test it, but it should work.
        If you like you can add loggers to track everything.
        i.e.
        Code:
        i=0;
        if (msg['MSH']['MSH.9']['MSH.9.1'].toString() == 'ADT')  {
        logger.info('found ADT');
             for each(nte in msg.NTE)  {
        i++;
                  if (nte['NTE.2']['NTE.2.1'].toString() == 'X')     {
        logger.info('found an X in NTE.2.1, on NTE number: ' + i);
        logger.info('String that was found: ' + nte['NTE.3']['NTE.3.1'].toString());
        nte['NTE.3']['NTE.3.1'] = "";
        logger.info('String that should be blank: ' + nte['NTE.3']['NTE.3.1'].toString());
        }
        }
        logger.info('Found ' + i +' NTE segments');
        }
        NOTE: the if for the ADT didn't have a () after toString. Maybe it wasn't seeing the ADT? copy the above and try it out.

        Comment


        • #5
          Originally posted by stormcel View Post
          well, I didn't test it, but it should work.
          If you like you can add loggers to track everything.
          i.e.
          Code:
          i=0;
          if (msg['MSH']['MSH.9']['MSH.9.1'].toString() == 'ADT')  {
          logger.info('found ADT');
               for each(nte in msg.NTE)  {
          i++;
                    if (nte['NTE.2']['NTE.2.1'].toString() == 'X')     {
          logger.info('found an X in NTE.2.1, on NTE number: ' + i);
          logger.info('String that was found: ' + nte['NTE.3']['NTE.3.1'].toString());
          nte['NTE.3']['NTE.3.1'] = "";
          logger.info('String that should be blank: ' + nte['NTE.3']['NTE.3.1'].toString());
          }
          }
          logger.info('Found ' + i +' NTE segments');
          }
          NOTE: the if for the ADT didn't have a () after toString. Maybe it wasn't seeing the ADT? copy the above and try it out.


          It seems to have been the first example was missing the "i=0;" at the beginning. I noticed it on the 2nd example, added it, and now it works. Thank you again!

          Comment

          Working...
          X