Announcement

Collapse
No announcement yet.

Deleting Components in Message

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

  • Deleting Components in Message

    Hello,

    Is there a way to iterate through the components in message and delete them.

    In this specific example, I want to iterate through a PID-13 segment and delete all components beyond PID-13.7. I could hardcode it, but sometimes the messages have 14 components other times they have a different value. I am just trying to keep it clean ...


    Code:
    for(var i=7; i<msg['PID']['PID.13'].length();i++){
    	index = 'PID.13.' + i+1;
    	delete msg['PID']['PID.13'][index];
    }
    Chuck Citrano

    [url][/http://www.tangible.comurl]

  • #2
    You've got the right idea; you just need to go one level further when testing the length of the child node list:

    Code:
    for each (component in msg.PID['PID.13'].children())
    	if (parseInt(component.name().toString().substr(7),10) >= 7)
    		delete msg.PID['PID.13'][component.name().toString()];
    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

    Nicholas Rupley
    Work: 949-237-6069
    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


    - How do I foo?
    - You just bar.

    Comment


    • #3
      Nick,

      I'm trying to do this same thing for the NK1 segment which could have repeating segments. I've tried to modify the code to use an iterator but I'm missing something. Can you see what I'm doing wrong ...

      for(var i=0; i<msg['NK1'].length();i++){
      for each (component in msg.NK1[i]['NK1.5'].children()) {
      if (parseInt(component.name().toString().substr(7),10 ) > 7)
      delete msg.NK1[i]['NK1.5'][component.name().toString()];
      }
      }
      Chuck Citrano

      [url][/http://www.tangible.comurl]

      Comment


      • #4
        I think I got it ...

        for each (nk1 in msg..NK1) {
        for each (component in nk1['NK1.5'].children()) {
        if (parseInt(component.name().toString().substr(6),10 ) > 7)
        delete nk1['NK1.5'][component.name().toString()];
        }
        }
        Chuck Citrano

        [url][/http://www.tangible.comurl]

        Comment


        • #5
          Originally posted by [email protected] View Post
          Nick,

          I'm trying to do this same thing for the NK1 segment which could have repeating segments. I've tried to modify the code to use an iterator but I'm missing something. Can you see what I'm doing wrong ...
          Your substr call is probably returning an empty string because the length of the component QName is less than 8 (for components 1 through 9 anyway). Slide the starting index back and it should work.
          Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

          Nicholas Rupley
          Work: 949-237-6069
          Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


          - How do I foo?
          - You just bar.

          Comment

          Working...
          X