web stats
Blanking repeating segment's field based on conditions - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 11-26-2019, 10:49 AM
Ozz Ozz is offline
Mirth Newb
 
Join Date: Apr 2015
Posts: 19
Ozz is on a distinguished road
Default 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'] = "";

}}
Reply With Quote
  #2  
Old 11-26-2019, 11:22 AM
stormcel stormcel is offline
OBX.3 Kenobi
 
Join Date: Mar 2010
Location: Phoenix
Posts: 160
stormcel is on a distinguished road
Default

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 at 12:42 PM.
Reply With Quote
  #3  
Old 11-26-2019, 11:31 AM
Ozz Ozz is offline
Mirth Newb
 
Join Date: Apr 2015
Posts: 19
Ozz is on a distinguished road
Default

Quote:
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?
Reply With Quote
  #4  
Old 11-26-2019, 12:51 PM
stormcel stormcel is offline
OBX.3 Kenobi
 
Join Date: Mar 2010
Location: Phoenix
Posts: 160
stormcel is on a distinguished road
Default

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.
Reply With Quote
  #5  
Old 11-26-2019, 01:09 PM
Ozz Ozz is offline
Mirth Newb
 
Join Date: Apr 2015
Posts: 19
Ozz is on a distinguished road
Default

Quote:
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!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 12:45 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation