on 2023 Jun 29 12:39 PM
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
Request clarification before answering.
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;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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/">',""> ;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.