on 2024 Dec 18 7:37 AM
I have a xml payload in that xml payload with two persons details .by using router how we can get one person's details as output. I tried router condition with xml & non-xml type, the output comes as total xml with 2persons details. How we can achieve one person details as output. only with router conditions no other pallets used here. the condition i used "/PersonalDetails/PersonalDetail/PersonalID = '9652' "
<PersonalDetails>
<PersonalDetail>
<PersonalID>9652</PersonalID>
<Name>vishu</Name>
<Pnumber>76546657568</Pnumber>
<Email>smoething@gmail.com</Email>
<State>AndhraPradesh</State>
<Martialstatus>No</Martialstatus>
<Job>Software Engineer</Job>
</PersonalDetail>
<PersonalDetail>
<PersonalID>6789</PersonalID>
<Name>ramki</Name>
<Pnumber>765426567568</Pnumber>
<Email>nothing@gmail.com</Email>
<State>Arunchalpradesh</State>
<Martialstatus>yes</Martialstatus>
<Job>Architecture</Job>
</PersonalDetail>
</PersonalDetails>
Request clarification before answering.
Hi @VAMSIKRISHNAKALE
I believe you are confused, the "Router" step is used to make a decision on which path your flow must take.
But from your explanation it seems what you want to achieve is filtering the data based on certain criteria so that the output is only the Nodelist that is matching your condition.
To achieve this there are multiple options:
A) Filter Step
B) Graphical Message Mapping
C) Groovy Script
D) XSLT Mapping
E) Split + Router
I will cover options A and C as I believe this are the best way to achieve it.
Option A (Simple): Standard functionality of Cloud Integration
Step 1: Store the value for PersonalID in a property
Note: In my case is static but the idea is that you can set the value dynamically
Step 2: Using "Filter" step filter the content based on a property.
Option C (Powerful): Leverage the advantages of Groovy to read and filter the information based on any property, header, or data within the payload itself.
Step 1: Store the value for PersonalID in a property
Step 2: Using "Groovy Script" filter the content based on a property.
import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.xml.XmlUtil;
def Message processData(Message message) {
//Get properties
def properties = message.getProperties()
// Read payload
Reader reader = message.getBody(Reader)
// Parse payload
def parsedXml = new XmlSlurper().parse(reader)
// Get the value for PersonalID you are looking
def personID = properties.get("personalId")
// Filter the XML based on this value
def filteredNode = parsedXml.PersonalDetail.find { it.PersonalID.text() == personID }
// Serialize
def filteredXml = XmlUtil.serialize(filteredNode)
// Return the ouput XML as new Payload
message.setBody(filteredXml)
return message;
}
Result using "Filter"
Result using Groovy
You can find the iFlow in the following link https://mega.nz/file/qhBQgBKC#Ieyrc_70nkAO_1cOSp9-8zkZ1KdKQZn7LQ7wRhPq4jY
Best regards 🖖🏻
Ricardo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 17 | |
| 8 | |
| 8 | |
| 6 | |
| 4 | |
| 4 | |
| 3 | |
| 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.