on 2025 Jan 30 1:47 PM
Hi Experts,
I need to replace all the payScaleArea codes with payScaleArea names for further processing. Considering performance, I don't want to use a looping process call with a splitter as there are more than 5L+ user IDs from CE Query. So I am fetching all the payScaleArea from payScaleArea OData API initiating the HashMap and retrieving it for the target structure.
Step:1 Source XMl will be the body
<queryCompoundEmployeeResponse>
<CompoundEmployee>
<id>11111</id>
<person>
<person_id_external>ABCDEF</person_id_external>
<employment_information>
<action>NO CHANGE</action>
<last_modified_on>2024-01-13T07:41:27.000Z</last_modified_on>
<user_id>ABCDEF-1</user_id>
<job_information>
<payScaleArea>ESP/EV</payScaleArea>
</job_information>
<job_information>
<payScaleArea>ESP/EM</payScaleArea>
</job_information>
<job_information>
<payScaleArea>ESP/EL</payScaleArea>
</job_information>
</employment_information>
</person>
<execution_timestamp>2025-01-30T06:26:34.000Z</execution_timestamp>
<version_id>1.0</version_id>
</CompoundEmployee>
</queryCompoundEmployeeResponse>
Step:2 Initiated the HashMap and stored the values in the property
hashmapOutput={ESP/EM\=aaaaaa, ESP/EL\=bbbbb, ESP/EV\=ccccc, ESP/EN\=ddddd}
Step:3 Target Body
<queryCompoundEmployeeResponse>
<CompoundEmployee>
<id>11111</id>
<person>
<person_id_external>ABCDEF</person_id_external>
<employment_information>
<action>NO CHANGE</action>
<last_modified_on>2024-01-13T07:41:27.000Z</last_modified_on>
<user_id>ABCDEF-1</user_id>
<job_information>
<payScaleArea>ESP/EV:ccccc</payScaleArea>
</job_information>
<job_information>
<payScaleArea>ESP/EM:aaaaa</payScaleArea>
</job_information>
<job_information>
<payScaleArea>ESP/EL:bbbbb</payScaleArea>
</job_information>
</employment_information>
</person>
<execution_timestamp>2025-01-30T06:26:34.000Z</execution_timestamp>
<version_id>1.0</version_id>
</CompoundEmployee>
</queryCompoundEmployeeResponse>
Step:4 Retrieve the HashMap and replace all the payScaleArea values to create the target body above
import com.sap.gateway.ip.core.customdev.util.Message;
def Message processData(Message message) {
def body = message.getBody(java.lang.String);
def map = message.getProperties();
def hmap1 = map.get("hashmapOutput");
def Root = new XmlParser().parseText(body);
Root.CompoundEmployee.each{CE ->
CE.person.employment_information.each{EMP->
EMP.job_information.each{JOB->
if (hmap1.containsKey(JOB.payScaleArea)){
JOB.payScaleArea[0].value = hmap1.get(JOB.payScaleArea[0].text().toString())
}
}
}
}
message.setBody(XmlUtil.serialize(Root));
return message;
}
The values itself is not getting replaced.
Any leads will be invaluable.
Regards,
Pavan
Request clarification before answering.
Check this --
GroovyIDE
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
73 | |
21 | |
8 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.