web stats
Trouble removing repeated field components if present - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-01-2015, 06:46 AM
Ozz Ozz is offline
OBX.1 Kenobi
 
Join Date: Apr 2015
Posts: 48
Ozz is on a distinguished road
Default Trouble removing repeated field components if present

Hello all,

I'm having issues paring down NK1 fields for outbound transmission. I hope the following explains it all. If not, I can elaborate on anything necessary.



I often receive an NK1.4 value with a 2nd iteration containing a default state/zip, such as:

1000 Main Street^^BOSTON^MA^12345~^^^MA^00000



What I want to do is to pare that down to display only as:

1000 Main Street^^BOSTON^MA^12345



The code I have in place currently works WHEN the repeated iterations present. When it's not, it causes errors. My code below also extends to delete other components which follow the zip code, FYI. This works properly, but I also need to expand on that to delete earlier fields in only the repeated iterations.


The bolded portion below is what I'm trying to work with to get what I need.



// this is to only pass fields NK1.1, NK1.2, NK1.3, NK1.4 in the first iteration of the NK1.4 field, for all iterations of the NK1 segment. All other components will be deleted.

if (msg['NK1']['NK1.4'].toString().length != 0)
{
i = 0;
while(msg['NK1']['NK1.4'][i] != undefined)
{
msg['NK1']['NK1.4'][i]['NK1.4.6'] = '';
msg['NK1']['NK1.4'][i]['NK1.4.7'] = '';
msg['NK1']['NK1.4'][i]['NK1.4.8'] = '';
msg['NK1']['NK1.4'][i]['NK1.4.9'] = '';
i++;
}


if (msg['NK1'][1]['NK1.4'][1]['NK1.4.4'].toString().length != 0)
{
msg['NK1'][1]['NK1.4'][1]['NK1.4.5'] = '';
msg['NK1'][1]['NK1.4'][1]['NK1.4.4'] = '';
}
}

}


My error is below. Cannot read property "NK1.4.4" from undefined. The message in question does NOT have the repeated component value, meaning my IF statement doesn't appear to recognize this and still tries to apply the
action. Possibly because I'm assigning the [1] iteration, but if I instead assign it the [i] value, I find that it doesn't perform my statement at all. So I either get errors, or my statement does nothing.

I am considering two solutions, though I'm not sure how to create either:
1) Instead of comparing to "not undefined", compare to criteria which better recognizes whether or not the field exists
2) Write a statement to say that NK1[i]NK1.4 (field 4 for ALL iterations of NK1 segments) should equal only the first example of a value passed in NK1.4 and NONE of the repeating values (if any).

The 2nd idea sounds like it would work to me, I just can't figure out how to write it to both iterate over all NK1 segments while at the same time assigning a value of an iterated field.



Now, the error:


Transformer error
ERROR MESSAGE: Error evaluating transformer
691: msg['NK1']['NK1.4'][i]['NK1.4.9'] = '';
692: i++;
693: }
694: }
695:
696: if (msg['NK1'][1]['NK1.4'][1]['NK1.4.4'].toString().length != 0)
697: {
698: msg['NK1'][1]['NK1.4'][1]['NK1.4.5'] = '';
699: msg['NK1'][1]['NK1.4'][1]['NK1.4.4'] = '';
700: }
LINE NUMBER: 696
DETAILS: TypeError: Cannot read property "NK1.4.4" from undefined

Last edited by Ozz; 05-01-2015 at 08:02 AM.
Reply With Quote
  #2  
Old 05-05-2015, 12:30 PM
Ozz Ozz is offline
OBX.1 Kenobi
 
Join Date: Apr 2015
Posts: 48
Ozz is on a distinguished road
Default

If anybody comes across this, I still haven't found a solution
Reply With Quote
  #3  
Old 05-06-2015, 09:22 AM
cward cward is offline
 
Join Date: Feb 2008
Posts: 84
cward is an unknown quantity at this point
Default

try this


for(i=msg['NK1']['NK1.4'].length();i>1;i--){
delete msg['NK1']['NK1.4'][i-1];
}
Reply With Quote
  #4  
Old 05-07-2015, 06:21 AM
Ozz Ozz is offline
OBX.1 Kenobi
 
Join Date: Apr 2015
Posts: 48
Ozz is on a distinguished road
Default

Quote:
Originally Posted by cward View Post
try this


for(i=msg['NK1']['NK1.4'].length();i>1;i--){
delete msg['NK1']['NK1.4'][i-1];
}
Running that after my script did the trick. Thank you very much!
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 08:42 AM.


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