title: How to call Sequence mediator inside the script mediator in WSO2 ESB
body: <p>I am going to call multiple WSO2 ESB Sequence mediator using under the script mediator. This will loop by following XML tag format. Based on the sequencename, it will loop. I need to call sequence according to this xml tag value.</p>
  
  <pre><code>&lt;message&gt;
    &lt;postCallSequences&gt;
           &lt;order&gt;1&lt;/order&gt;
           &lt;sequencename&gt;gov:/repository/sequences/AB_SQ.xml&lt;/sequencename&gt;
        &lt;/postCallSequences&gt;
        &lt;postCallSequences&gt;
           &lt;order&gt;2&lt;/order&gt;
           &lt;sequencename&gt;gov:/repository/sequences/XY_SQ.xml&lt;/sequencename&gt;
     &lt;/postCallSequences&gt;
  &lt;/message&gt;
  </code></pre>
  
  <p>I have loop above XML like following script mediator.</p>
  
  <pre><code>var xmlDoc = new XML("XML_STRING_HERE");
  
  for each (var p in xmlDoc..*::postCallSequences){
   var sequencename = p.sequencename.toString();
   var seq = mc.getSequence(sequencename);
   seq.mediate(mc);
   //seq.get(0).mediate(mc);
  }
  </code></pre>
  
  <p>But it not fully running, it showing following error message.</p>
  
  <pre><code>[2019-03-25 14:39:31,960] [EI-Core] ERROR - SequenceMediator Error while building message. null
  java.lang.ClassCastException
  [2019-03-25 14:39:31,960] [EI-Core] ERROR - CommonScriptMessageContext Error while building message. null
  java.lang.ClassCastException
  [2019-03-25 14:39:31,973] [EI-Core] ERROR - ScriptMediator The script engine returned an error executing the inlined js script function mediate
  com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.WrappedException: Wrapped org.apache.synapse.SynapseException: Error while building message. null (&lt;Unknown Source&gt;#21) in &lt;Unknown Source&gt; at line number 21
      at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:68)
      at javax.script.CompiledScript.eval(CompiledScript.java:92)
      at org.apache.synapse.mediators.bsf.ScriptMediator.mediateForInlineScript(ScriptMediator.java:394)
      at org.apache.synapse.mediators.bsf.ScriptMediator.invokeScript(ScriptMediator.java:289)
      at org.apache.synapse.mediators.bsf.ScriptMediator.mediate(ScriptMediator.java:257)
      at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:108)
  </code></pre>
  
  <p>I have refered following link as well. Still issue there. <a href="https://itasyurt.wordpress.com/2014/06/03/reusing-mediators-through-scripting-in-wso2-esb/" rel="nofollow noreferrer">link</a></p>