Announcement

Collapse
No announcement yet.

Using variable in delete msg funtion?

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

  • Using variable in delete msg funtion?

    I am trying to delete all segments except the MSH and PID in a message and trying to pass a variable to the delete msg function but it always errors out. If I explicitly put the segment name though, it works...

    Am I doing something wrong?

    Thanks,

    David

    for each (seg in msg.children()) {
    var segname = seg.name().toString();
    if (seg.name().toString() != "MSH" || seg.name().toString() != "PID" || seg.name().toString() != "EVN") {
    delete msg['PV1']; works
    delete msg[seg.name().toString()]; doesnt work
    delete msg[segname]; doesnt work
    }
    }

  • #2
    Try this think you need to replace the || with && when using the Not equal. The following code worked for me:

    for each (seg in msg.children()) {
    if (seg.name().toString() != "MSH" && seg.name().toString() != "EVN" && seg.name().toString() != "PID") {
    delete msg[seg.name()];
    }
    }

    Comment


    • #3
      Thanks! That was it.

      Also I didnt need the toString in the seg.name.

      Comment

      Working...
      X