title: How to loop and combine as one in Mule Dataweave
body: <p>I have request of json and expected response one as mentioned below. It need to groupBy <code>clientItemCode</code> and i'm  halfway somewhere stuck to loop around in same. Used both <code>MapObject</code> and <code>reduce</code> combination of function. Any help will be appreciated.</p>
  
  <pre><code>[
  {
    "ClientCode": "1",
    "ClientItemCode": "245",
    "LocationId": "CLOSED"
   },
   {
    "ClientCode": "1",
    "ClientItemCode": "245",
    "LocationId": "OPEN"
   },
      {
    "ClientCode": "2",
    "ClientItemCode": "245",
    "LocationId": "CHECKOUT"
   },
   {
    "ClientCode": "2",
    "ClientItemCode": "245",
    "LocationId": "TEST"
   },
   {
    "ClientCode": "1",
    "ClientItemCode": "123",
    "LocationId": "OPEN"
   },
   {
    "ClientCode": "1",
    "ClientItemCode": "123",
    "LocationId": "CLOSED"
   }
   ]
  </code></pre>
  
  <p>Expected Response:</p>
  
  <pre><code>  &lt;Results&gt;
    &lt;Result&gt;
      &lt;ClientItemCode&gt;123&lt;ClientItemCode&gt;
      &lt;ResultLines&gt;
        &lt;ResultLine&gt;
          &lt;ClientCode&gt;1&lt;/ClientCode&gt;
          &lt;From&gt;
            &lt;LocationId&gt;OPEN&lt;/LocationId&gt;
          &lt;/From&gt;
          &lt;To&gt;
            &lt;LocationId&gt;CLOSED&lt;/LocationId&gt;
          &lt;/To&gt;
        &lt;/ResultLine&gt;
         &lt;ResultLine&gt;
          &lt;ClientCode&gt;2&lt;/ClientCode&gt;
          &lt;From&gt;
            &lt;LocationId&gt;CHECKOUT&lt;/LocationId&gt;
          &lt;/From&gt;
          &lt;To&gt;
            &lt;LocationId&gt;TEST&lt;/LocationId&gt;
          &lt;/To&gt;
        &lt;/ResultLine&gt;
      &lt;/ResultLines&gt;
    &lt;/Result&gt;
    &lt;Result&gt;
     &lt;CientItemCode&gt;245&lt;ClientItemCode&gt;
     &lt;ResultLines&gt;
        &lt;ResultLine&gt;
          &lt;ClientCode&gt;1&lt;/ClientCode&gt;
          &lt;From&gt;
            &lt;LocationId&gt;CLOSED&lt;/LocationId&gt;
          &lt;/From&gt;
          &lt;To&gt;
            &lt;LocationId&gt;OPEN&lt;/LocationId&gt;
          &lt;/To&gt;
       &lt;/ResultLine&gt;
      &lt;/ResultLines&gt;
    &lt;/Result&gt;
  &lt;/Results&gt;
  </code></pre>