on 07-28-2019 6:27 PM
Hello,
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
See i/p XML below.
<SAPCpiOutboundPartnerRole>
<orderId>0000490025</orderId>
<entryNumber>-1</entryNumber>
<partnerId>11111</partnerId>
<documentAddressId>1</documentAddressId>
<partnerRoleCode>WE</partnerRoleCode>
<integrationKey>-1|0000490025</integrationKey>
</SAPCpiOutboundPartnerRole>
<SAPCpiOutboundPartnerRole>
<orderId>0000490025</orderId>
<entryNumber>-1</entryNumber>
<partnerId>44444</partnerId>
<documentAddressId/>
<partnerRoleCode>AG</partnerRoleCode>
<integrationKey>-1|0000490025</integrationKey>
</SAPCpiOutboundPartnerRole>
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.
Hi Saket,
Context of partnerId and partnerRoleCode must be outer node of SAPCpiOutboundPartnerRole so that function extractShipToSoldTo will receive all the Partner IDs and Partner Role Codes together. Then, extractShipToSoldTo function can loop over Partner Role Codes and map them as required.
def void extractShipToSoldTo(String[] partnerIds, String[] partnerRoleCodes, Output shipToNumber, Output soldToNumber, MappingContext context) {
partnerRoleCodes.eachWithIndex { partnerRoleCode, index ->
switch (partnerRoleCode) {
case 'WE':
shipToNumber.addValue("SHIPTO${partnerIds[index]}");
break
case 'AG':
soldToNumber.addValue("SOLDTO${partnerIds[index]}");
break
}
}
}
Hope this helps,
Bala
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
79 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.