Announcement

Collapse
No announcement yet.

Repeating fields causing problems while parsing

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

  • 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, 12:50 AM. Reason: typo

  • #2
    do you only want the first value?

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

    Comment


    • #3
      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,""

      Comment


      • #4
        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']);
            }

        Comment


        • #5
          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.

          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.

          Comment

          Working...
          X