cancel
Showing results for 
Search instead for 
Did you mean: 

CPI Message mapping problems with arrays

manu_maca30
Explorer
0 Kudos
424

Hello Experts,

 

I have the following incoming part of a payload from provider:
...

<acceptedDeclarationOfConsentVersion/>

<dealers>0c0c4930-a014-11e5-94f6-d8913b26e8a6</dealers>
<dealers>d1f822e0-92a4-11e5-9da5-b6f686ff8cf4</dealers>
<preferredCountry>CN</preferredCountry>

..

In the message mapping I have the following:

manu_maca30_0-1723670101312.png

The problem is, that instead of writing the dealers in the result mapping as following:
<to_dealernr>
<dealerNumber>0c0c4930-a014-11e5-94f6-d8913b26e8a6</dealerNumber>
</to_dealernr>
<to_dealernr>
<dealerNumber>d1f822e0-92a4-11e5-9da5-b6f686ff8cf4</dealerNumber>
</to_dealernr>

They are instead written like this, both under 1 node and the second node empty ..:
<to_dealernr>
<dealerNumber>0c0c4930-a014-11e5-94f6-d8913b26e8a6</dealerNumber>
<dealerNumber>d1f822e0-92a4-11e5-9da5-b6f686ff8cf4</dealerNumber>
</to_dealernr>
<to_dealernr></to_dealernr>

And this is causing issues on API side as the XML is not correctly generated and the API cannot interpret the dealerNumber property when it's not in the correct format.


My question is, what can I do within the mapping in order to achieve the desired mapping which is:
<to_dealernr>
<dealerNumber>0c0c4930-a014-11e5-94f6-d8913b26e8a6</dealerNumber>
</to_dealernr>
<to_dealernr>
<dealerNumber>d1f822e0-92a4-11e5-9da5-b6f686ff8cf4</dealerNumber>
</to_dealernr>

Thanks in advance.



View Entire Topic
Ryan-Crosby
Active Contributor

You can use this XSLT as the initial step to get the desired XML structure and then accommodate in your IA mapping.  The only thing it does is expand the structure and copy everything else as is.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:mode on-no-match="shallow-copy"/>
    <xsl:template match="dealers">
      <to_dealernr>
        <dealerNumber><xsl:value-of select="."/></dealerNumber>
      </to_dealernr>
    </xsl:template>
</xsl:stylesheet>

 

Regards,

Ryan Crosby

manu_maca30
Explorer
0 Kudos

I have tried that now, but it seems the behaviour is the following:
1) I made dealerNumber 0 to 1 and mapped dealers -> dealerNumber only but like this it does not map the dealers at all.

2) I mapped dealers to to_dealernr and also to dealerNumber but in this case I have the same behaviour as before .. just that only 1 dealer number is present in the dealerNumber field .. 

manu_maca30_0-1723702242478.png

Could I achieve the proper result with a groovy script ? 
Thanks in advance.

 

Ryan-Crosby
Active Contributor
0 Kudos
@manu_maca30 yes, but an XSLT is much easier.
manu_maca30
Explorer
0 Kudos

Hello,

I agree, but I cannot seem to find the right combination to make it work..
If you have other suggestions I will gladly try them out.

Thanks!

Ryan-Crosby
Active Contributor
0 Kudos
@manu_maca30 I've updated the answer to include a pre-XSLT that you can execute to get the desired structure.
manu_maca30
Explorer
0 Kudos

Hello Ryan,

First of all thanks for your support. 
So you are saying I can use the XSLT script before the IA mapping to get the desired xml and then do the mapping.

That means I should create the XSLT mapping before my message mapping correct ? 
I just want to make sure I understood what you are referring to.

manu_maca30_0-1723727656132.png

Thanks again!

manu_maca30
Explorer
Managed to make it work, thanks Ryan!
Ryan-Crosby
Active Contributor
0 Kudos
@manu_maca30 yes, correct... but you will also need to remember to alter your source schema for IA so it matches the target for the to_dealernr/dealerNumber portion, and map the source to target directly.