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

a xml with two persons details, by using router condition how we can achieve one persons details?

VAMSIKRISHNAKALE
Explorer
0 Kudos
310

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>

Accepted Solutions (1)

Accepted Solutions (1)

MAVR
Product and Topic Expert
Product and Topic Expert
0 Kudos

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
MAVR_5-1734597975685.png

Step 2: Using "Filter" step filter the content based on a property.

MAVR_0-1734597146694.png

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.

MAVR_2-1734597365457.png

 

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"

MAVR_3-1734597570494.png

Result using Groovy

MAVR_4-1734597618552.png

You can find the iFlow in the following link https://mega.nz/file/qhBQgBKC#Ieyrc_70nkAO_1cOSp9-8zkZ1KdKQZn7LQ7wRhPq4jY

Best regards 🖖🏻
Ricardo

 

VAMSIKRISHNAKALE
Explorer
0 Kudos

Hi Ricardo, 
yes, I little bit confusion about this but your explanation clears my doubts.
thank you so much for your clarification.

Answers (0)