on ‎2022 Dec 11 4:44 AM
Dear Experts,
I need to replace couple of elements in the input message and for that I am using following script. But surprisingly only the last function is giving the correct output. Please suggest if I am missing anything here.
I am getting correct result for only - HierarchyLevel .
Input
<Records>
<TenantCode>900</TenantCode>
<HierarchyCode>7</HierarchyCode>
<HierarchyName>Test</HierarchyName>
<HierarchyLevel>1</HierarchyLevel>
</Records>
<Records>
<TenantCode>901</TenantCode>
<HierarchyCode>6</HierarchyCode>
<HierarchyName>Test</HierarchyName>
<HierarchyLevel>0</HierarchyLevel>
</Records>
Script
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
def body = message.getBody(String) as String;
message.setBody(body.replaceAll("TenantCode","ns2:TenantCode"))
message.setBody(body.replaceAll("HierarchyCode","ns2:HierarchyCode"))
message.setBody(body.replaceAll("HierarchyName","ns2:HierarchyName"))
message.setBody(body.replaceAll("HierarchyLevel","ns2:HierarchyLevel"))
return message;
}
Br,
Arvik
Request clarification before answering.
Hi Arvik
You are using the original String body object from the first statement with each replace function (setBody function isn't updating the string object from the first statement).
Instead, use something like this:
def body = message.getBody(String) as String;
body = body.replaceAll("TenantCode","ns2:TenantCode");
body = body.replaceAll("HierarchyCode","ns2:HierarchyCode");
body = body.replaceAll("HierarchyName","ns2:HierarchyName");
body = body.replaceAll("HierarchyLevel","ns2:HierarchyLevel");
message.setBody(body);
Thanks,
Marty
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 5 | |
| 5 | |
| 4 | |
| 4 | |
| 2 | |
| 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.