Can I use appendChild or other function in a script mediator in WSO2 ESB 6.5?

163 Views Asked by At

I am trying to build a payload in html in order to send an email. I am using a script mediator but I want to append a child if a condition is true.

<script language="js">
<![CDATA[var payload = <html>
            <div id="main">
                <div>
                    ......
                </div>
                <div>
                    .......
                </div>
            </div>
       </html>;
       
var child =  <div>
               ....
                </div>
if(true){
     payload.getElementById("main").appendChild(child);
}
        mc.setPayloadXML(payload);]]>
</script>

I have tried with appendChild(a fragment of html) but I got the next error:

Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function getElementById in object

How can I append a child to a div?

Thank you

0

There are 0 best solutions below