web stats
Repeating fields causing problems while parsing - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 11-17-2015, 01:35 AM
gkittlaus gkittlaus is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Posts: 104
gkittlaus is on a distinguished road
Default Repeating fields causing problems while parsing

Hi,

I have a "little" problem with putting my messages in a MySQL Database.

When I receive a message I assign the content to variables vias javascript like
Code:
pID = msg['PID']['PID.3']['PID.3.1'].toString()
afterwards, I build an insert or update string for MySQL and put my variables in there. works great to be honest.

BUT, sometimes I receive messages, where fields like address or phonenumber are repeated via a ~ charakter.

So sometime I receive this as a phonenumber:
...|012345678|...
and sometime this:
...|012345678~987543|...

The first example works well. No problems.

But the second one gives me a headache.
Instead of a normal phonenumber I get this
"<PID.13.1>012345678</PID.13.1><PID.13.1>987543</PID.13.1>"
In my channel I already tried to switch of subfield and repetitive parsing, but no change.

Can someone give me a hint here?

Last edited by gkittlaus; 11-17-2015 at 01:50 AM. Reason: typo
Reply With Quote
  #2  
Old 11-17-2015, 06:16 AM
mcalKno mcalKno is offline
 
Join Date: Apr 2015
Location: Pennsylvania
Posts: 247
mcalKno is on a distinguished road
Default

do you only want the first value?

Code:
pID = msg['PID']['PID.3'][0]['PID.3.1'].toString();
Reply With Quote
  #3  
Old 11-18-2015, 02:08 AM
bobekos bobekos is offline
OBX.1 Kenobi
 
Join Date: Oct 2014
Posts: 26
bobekos is on a distinguished road
Default

Do you need the tilde sign? When not you can try this:
PHP Code:
pID msg['PID']['PID.3']['PID.3.1'].toString().replace(/~/g,""
or replace all signs after tilde:
PHP Code:
pID msg['PID']['PID.3']['PID.3.1'].toString().replace(/~.*/g,""
Reply With Quote
  #4  
Old 11-18-2015, 03:38 AM
MrGesan MrGesan is offline
OBX.1 Kenobi
 
Join Date: Jul 2011
Location: Italy
Posts: 27
MrGesan is on a distinguished road
Default

PHP Code:
var phoneNumbers = new Array();

for 
each(seg in msg.children())
{
    if (
seg.name().toString().equals("PID"))
    {
        for 
each(phoneSeg in seg['PID.13'])
            
phoneNumbers.push(phoneSeg['PID.13.1']);
    }

Reply With Quote
  #5  
Old 11-23-2015, 05:29 AM
gkittlaus gkittlaus is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Posts: 104
gkittlaus is on a distinguished road
Default

Quote:
Originally Posted by mcalKno View Post
do you only want the first value?

Code:
pID = msg['PID']['PID.3'][0]['PID.3.1'].toString();

This one would fail if there was no PID Segment at all. I know, this should not happen at all, but from a coding perspective it's not what I am looking for.

Quote:
Originally Posted by MrGesan View Post
PHP Code:
var phoneNumbers = new Array();

for 
each(seg in msg.children())
{
    if (
seg.name().toString().equals("PID"))
    {
        for 
each(phoneSeg in seg['PID.13'])
            
phoneNumbers.push(phoneSeg['PID.13.1']);
    }

I kind of did it like you. But I just went thorugh the first loop. So I made an extra increment as 0 and count it up per loop. Once it reached the 1, an IF Statement checked this and made a "break" or "continue" on the loop... can not remeber what of those I have chosen.
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 06:38 PM.


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