Mirth Connect 4.0.1 Released!

Mirth Connect 4.0.1 is now available as an appliance update and on our GitHub page. Mirth Connect 4.0.1 is a patch release containing a bug fix which includes fixing a Jetty keystore regression that caused Connect servers using a PKCS12 keystore containing a wildcard certificate and/or a certificate with a SAN to throw an exception on startup. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

appendChild is not a function

  • Filter
  • Time
  • Show
Clear All
new posts

  • appendChild is not a function


    A few hours ago I came across this weird problem where I cant use appendChild, setChildren, createSegment etc.
    Whenever I try to use the code below, I get TypeError: appendChild is not a function, it is xml.

    tmp['Request']['Events']['Event']['Documents'].appendChild(new XML('<Document></Document>'));
    var document = tmp['Request']['Events']['Event']['Documents']['Document']
    I've seen people use createSegment to create a new XML segment, but that gives me undefined as return value.

  • #2
    Here is a very simple example of using appendChild to add a node which should help you figure out how to use it for what you are doing.

    x = new XML('<MSG><Node1/></MSG>');
    x.appendChild(new XML('<Node2/>'));


    • #3
      I have tried that code and it works fine. However I'm still not sure why my code fails.
      All i'm trying to do is add a child to a node in the outbound template.


      • #4
        Post your outbound template, I am guessing it is off. Your code would work with this in your outbound template (which is of type XML in this case)

        Last edited by pacmano; 03-23-2021, 07:37 AM.
        Diridium Technologies, Inc.


        • #5
          To elaborate on what pacmano said, you can't call appendChild on a node that doesn't exist.
          Here's another approach that might work better depending on how you're building the rest of your message.
          var documents = <Documents/>;
          tmp.Request.Events.Event.Documents = documents;


          • #6
            I managed to solve the problem using createSegment. I'm still not sure why it didn't work with appendChild though


            • #7
              Maybe try this...
              tmp['Events']['Event']['Documents'].appendChild(new XML('<Document/>'))
              tmp.Events.Event.Documents.Document = 'Document Here'
              var document = tmp.Events.Event.Documents.Document
              Last edited by jkrebs; 03-25-2021, 10:37 AM. Reason: Corrected new XML syntax


              • #8
                Originally posted by cevdamme View Post
                ... I'm still not sure why it didn't work with appendChild though
                You'll have to share what the value of tmp was before calling appendChild. As I said, you can't call it on a node that does not already exist. If you try to, it will throw the error you are seeing. pacmano gave a sample of a bare minimum template that includes the element to which you are trying to append a child. I gave an alternative method that will work even if the node doesn't already exist.