AnsweredAssumed Answered

How do I create repeating XML groups in a single XML document from a non-repeating input ?

Question asked by mark.springthorpe131988 on Feb 22, 2017
Latest reply on Sep 25, 2017 by steve_skripek082158

I have a JSON input document that I need to map to an XML (SAP IDOC) output document.

 

In the output document, I need to create 2 instances of an XML group (TOTALS) created from a single input value from the input JSON (value), e.g.

 

Input;

“Order”

{

    “orderNo”:”1234”,

    “value”:”9.99”

}

 

Output;

<SAPORDER>

   <HEADER>

       <ORDERNO>1234</ORDERNO>

  </HEADER>

  <TOTALS>

      <TOTALS-TYPE>AAAA</TOTALS-TYPE>

      <TOTAL-VAL>9.99</TOTALS-TYPE>

 </TOTALS>

  <TOTALS>

      <TOTALS-TYPE>BBBB</TOTALS-TYPE>

      <TOTAL-VAL>9.99</TOTALS-TYPE>

 </TOTALS>

</SAPORDER>

 

So, I need to create 2 <TOTALS> groups with different types – this is a contrived example, not the real thing.

 

I have approached this as follows;

 

  • Routed the input document to 2 sub-processes, and each sub-process creates a version of the <TOTALS> group, so that I end up with 2 new messages of;

  

  <HEADER>

       <ORDERNO>1234</ORDERNO>

  </HEADER>

  <TOTALS>

      <TOTALS-TYPE>AAAA</TOTALS-TYPE>

      <TOTAL-VAL>9.99</TOTALS-TYPE>

 </TOTALS>

 

And

 

  <HEADER>

       <ORDERNO>1234</ORDERNO>

  </HEADER>

  <TOTALS>

      <TOTALS-TYPE>BBBB</TOTALS-TYPE>

      <TOTAL-VAL>9.99</TOTALS-TYPE>

 </TOTALS>

 

I had to include the ORDERNO because I want to put them on a Document Cache, and this is the only identifier.

 

  • On the main flow, I combined these 2 separate documents it a single one, so I then had;

 

  <HEADER>

       <ORDERNO>1234</ORDERNO>

  </HEADER>

  <TOTALS>

      <TOTALS-TYPE>AAAA</TOTALS-TYPE>

      <TOTAL-VAL>9.99</TOTALS-TYPE>

 </TOTALS>

  <HEADER>

       <ORDERNO>1234</ORDERNO>

  </HEADER>

  <TOTALS>

      <TOTALS-TYPE>BBBB</TOTALS-TYPE>

      <TOTAL-VAL>9.99</TOTALS-TYPE>

 </TOTALS>

 

  • I then place this single combined document into a cache, keyed on the ORDERNO

 

  • In the main process's map, I then added a map function to pull the document from the cache (based on the ORDERNO on the original JSON document).

 

Originally I got the function output to be the <TOTALS> element, and mapped that to the output XML’s <TOTALS> element – hoping it would map at this top level.  It didn’t and just mapped nothing (null).

 

  • I then modified the function to output the lower level elements <TOTALS-TYPE> and <TOTALS-VAL>, and mapped to the corresponding elements on the output XML.

 

However, this only created an instance for <TOTALS-TYPE> of ‘AAAA’ and not ‘BBBB’ – which is not what I want.

 

How do I achieve what I want to do, because it seems to be a difficult thing to do L

Outcomes