web stats
remove extra components from a field (in a specific segment) - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-12-2013, 10:39 AM
Rahn Rahn is offline
Mirth Newb
 
Join Date: Aug 2010
Posts: 21
Rahn is on a distinguished road
Default remove extra components from a field (in a specific segment)

I am trying to pare down a element with extra components.

That is:
We're getting PID.11 with 15 components in it, and the destination can only accept 10 components.
input: PID.11 = |1^2^3^4^5^6^7^8^9^10^11^12^13^14^15|
desired output: |1^2^3^4^5^6^7^8^9^10|

I thought this would be pretty simple:
Code:
if (msg['PID']['PID.11'].length() > 10)
{
	for (var i=10; i<msg['PID']['PID.11'].length();i++)
	{
			delete msg['PID']['PID.11'][i];
			i--;
	}
}
Note the i--; is to re-index the element on each loop. I saw that on another message, although it doesn't make much sense to need that.

However, my transformed output is the same as the input.

I'm sure I'm missing something simple, so any help would be appreciated.
Reply With Quote
  #2  
Old 08-12-2013, 12:33 PM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,282
cory_cole is on a distinguished road
Default

if (msg['PID']['PID.11'].length() > 10)
{
msg['PID']['PID.11'] = msg['PID']['PID.11']['PID.11.1'] + msg['PID']['PID.11']['PID.11.2']...msg['PID']['PID.11']['PID.11.10']
}


Keep in mind the ... is not literal but a place holder for everything in between.
Reply With Quote
  #3  
Old 08-20-2013, 11:08 AM
Rahn Rahn is offline
Mirth Newb
 
Join Date: Aug 2010
Posts: 21
Rahn is on a distinguished road
Default

Thanks. This as been more of an adventure than it should have.

I spent some time trying variation of:

if (MSG.[PID].[PID11].length >= 10) {
//replace PID11
}

but the if check kept failing.
I tried setting the length to a variable, and comparing to that.
I trying converting it to a string, and comparing:
if (MSG.[PID].[PID11].length.toString() >= "10")

In the end, for now, I'm just always doing the simple substitution and not trying to check the length.

Thanks,
Reply With Quote
  #4  
Old 08-21-2013, 03:30 AM
DBE DBE is offline
OBX.1 Kenobi
 
Join Date: Sep 2011
Posts: 34
DBE is on a distinguished road
Default

Hello,

This code gives the expected result:
Code:
var i = 11;
while (msg['PID']['PID.11']['PID.11.'+i].length() > 0)
{
	delete msg['PID']['PID.11']['PID.11.'+i];
	i++;
}
The following code counts the number of repetitions of the field PID-11 and not the number of components.
Code:
msg['PID']['PID.11'].length()

Last edited by DBE; 08-21-2013 at 03:36 AM.
Reply With Quote
  #5  
Old 11-07-2013, 06:38 AM
Rahn Rahn is offline
Mirth Newb
 
Join Date: Aug 2010
Posts: 21
Rahn is on a distinguished road
Thumbs up Thanks

DBE,
A bit delayed, but thanks. That code works well.
Reply With Quote
Reply

Tags
component, element, remove, segment

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 09:54 AM.


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