cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to implement multimapping in CPI

Robert_d_Hoedt
Explorer
0 Kudos
3,203

Hi,

I would like to know what is the best way to implement multimapping in CPI.

My requirement is to map 1 message to 2 messages.

In the editor it looks like this

Senderside

<Messages>

<Message1>

........

</Message1>

<Messages>

and in the Receiverside

<Messages>

<Message1>

........

</Message1>

<Message2>

.........

<Message2>

<Messages>.

I created the mapping and tested it, For testing purposes i added the <messages><message1> tags to my message and the mapping worked.

For runtime i sent the message (without <messages><message1> tags ) and it failed.

I then looked for a solution and one suggestion was to add a Content Modifier to the iFlow for the message body:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<ns3:Messages xmlns:ns3="http://sap.com/xi/XI/SplitAndMerge">

<ns3:Message1>

${in.body}

</ns3:Message1>

</ns3:Messages>

I added the content modifier and now my mapping works.

But now i have a problem that the result message looks like this:

<Messages>

<Message1>

........

</Message1>

<Message2>

.........

<Message2>

<Messages>.

How do get rid of all these tags?

And is this really the best solution to my mapping requirement? It seems to me a very clumsy way of doing a multimap. (compared to the way it was done in PO)

Regards

Robert

Accepted Solutions (1)

Accepted Solutions (1)

Keylla_Lima
Product and Topic Expert
Product and Topic Expert

Hi Robert,

After the multimapping step you can also use a groovy script to remove that unwanted tags generated. Please see below:

import com.sap.gateway.ip.core.customdev.util.Message;

import java.util.HashMap;

import java.io.*;

def Message processData(Message message) {

//get Body

def body = message.getBody(java.lang.String) as String;

//replaceMultimap tag

body = body.replaceAll('<ns2:Messages xmlns:ns2="http://sap.com/xi/XI/SplitAndMerge">', "");

body = body.replaceAll("</ns2:Messages>", "");

body = body.replaceAll("<ns2:Message1>", "");

body = body.replaceAll("</ns2:Message1>","");

body = body.replaceAll("<ns2:Message2>", "");

body = body.replaceAll("</ns2:Message2>","");

body = body.replaceAll("<ns2:Message3>", "");

body = body.replaceAll("</ns2:Message3>","");

//set body

message.setBody(body);

return message;

}

Robert_d_Hoedt
Explorer
0 Kudos

Hi Keylla,

I tried your script and it works fine.

I have another script to write in much the same way only there i have string that allready contains double quotes (" ") and now the replace command gets confused and throws an error.

I want to do this:

body.replaceAll("<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">",""> ;

But that command throws an error. Maybe this is because of the " " surrounding the namespace?

Or the :// in the namespace?

If there is a solution to this that would be helpfull

Kr

Robert

ps. I allready found my answer; in the command replaceAll you can either use single quotes or double quotes, and thereby escaping the other one.

Answers (2)

Answers (2)

Keylla_Lima
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Robert,

Please try with single quote for the snippet you want to replace that has url with double quotes:

body.replaceAll('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">',""> ;
Robert_d_Hoedt
Explorer
0 Kudos

Hi Keylla,

Thx for your answer.

Incidentally i found the same somewhere else, but didnt see your answer yet.

Whichever way, thank you for helping me out.

Regards

Robert

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Robert ,

You can use content filter and trim these additional tags very easily.

Follow below to know more about content filter.

https://blogs.sap.com/2017/06/01/sap-cloud-platform-integration-content-filter-in-detail/

Regards,

Sriprasad S Bhat

Robert_d_Hoedt
Explorer
0 Kudos

Hi Sriprasad,

I read your blog but still no sure how to proceed.

The output of my message is

<ns3:Messages >

<ns3:Message1>

<ns2:SessionHeader >

<ns2:sessionId>xyz</ns2:sessionId>

</ns2:SessionHeader>

</ns3:Message1>

<ns3:Message2>

<ns2:setPurchaseOrderResult >

<ns2:assignmentId>1</ns2:assignmentId>

<ns2:success>true</ns2:success>

<ns2:message>message</ns2:message>

<ns2:purchaseOrderNr>123456789</ns2:purchaseOrderNr>

</ns2:setPurchaseOrderResult>

</ns3:Message2>

</ns3:Messages>

And what i need is like

<ns2:SessionHeader >

<ns2:sessionId>xyz</ns2:sessionId>

</ns2:SessionHeader>

<ns2:setPurchaseOrderResult >

<ns2:assignmentId>1</ns2:assignmentId>

<ns2:success>true</ns2:success>

<ns2:message>message</ns2:message>

<ns2:purchaseOrderNr>123456789</ns2:purchaseOrderNr>

</ns2:setPurchaseOrderResult>

Could you provide the correct XPATH to do that?

And i suppose it is NODE or NODELIST from the dropdown list?

Regards

Robert