Skip to Content
Jul 28, 2019 at 05:27 PM

Message Mapping - only 1st item in collection is read

507 Views Last edit Jul 28, 2019 at 05:44 PM 3 rev


A noob question.

I have an input XML that has a collection on items and I would like to extract specific values from this collection and push it to the output. I have seen some examples, but I am unable to extract from multiple items.

This is what I intend to do. Extract as

  • extract <partnerId> for partnerRoleCode = WE and map it to an o/p <shipToNumber>
  • extract <partnerId> for partnerRoleCode = AG and map it to an o/p <soldToNumber>

See i/p XML below.


The issue I am facing is that only the first <SAPCpiOutboundPartnerRole> seems to getting read in the groovy script.

def void extractShipToSoldTo(String[] is,String[] ps, Output shipToNumber, Output soldToNumber, MappingContext context) {
        //String value1 = context.getHeader(is[0]);
        //String value2 = context.getProperty(ps[0]);
        /*String s = "";
        for (int i = 0; i < is.length; i++){
            s = s + is[i].toString();
        if (is[0]=='WE'){
            shipToNumber.addValue('SHIPTO' + ps[0]);    
        if (is[0]=='AG'){
            soldToNumber.addValue('SOLDTO' + ps[0]);

This produces only either the soldToNumber or the shipToNumber when I test with the i/p XML as above. I have tried printing the values, but no luck.

What am I doing wrong ?

I think Message Mapping should be able to handle this simple case.

How do I solve this problem using Mapping.