0

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

Aprendiendo Siempre
  • 341
  • 1
  • 6
  • 18
  • Why don't you use PayloadFactory to build a html payload? – Maxim Fazyloff Dec 01 '20 at 11:37
  • I don't know, I found this solution and worked fine for me. If I use payload can resolve my question? How can I use an "if" in this solution? @MaximFazyloff – Aprendiendo Siempre Dec 02 '20 at 13:54
  • 1
    You can use "Switch" mediator to emulate "If" in mediation without using "Script" as it is not recommended for its slowing down the flow. If you give me 2 examples of a payload (with and without child) and a name of a variable to check in if, i can give a sample API for you to check. It would be super, if you could provide the whole sequence of your API/Proxy for better understanding. – Maxim Fazyloff Dec 03 '20 at 06:28
  • I have understood your answer, I would try this option, thank you so much – Aprendiendo Siempre Dec 03 '20 at 07:04

0 Answers0