Announcement

Collapse
No announcement yet.

remove extra components from a field (in a specific segment)

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

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

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

    Comment


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

      Comment


      • #4
        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, 03:36 AM.

        Comment


        • #5
          Thanks

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

          Comment

          Working...
          X