07-12-2022 02:29 AM
Hi Snaplogic professionals,
i have question how to design pipeline/condition properly. Lets say i would like to extract ‘Id’ of ‘Branch’, only if ‘Ident’ of current branch is “Capital”
iam able to get all ‘Idents’ in array - but is there a way how to solve it in one mapper?
<Business>
<Branch>
<Id>12345</Id>
<City>
<Ident>Capital<Ident>
</City>
</Branch>
<Branch>
<Id>44434</Id>
<City>
<Ident>NotCapital<Ident>
</City>
</Branch>
</Business>
so from xml snippet above, i would like to extract only 12345. now this value is on first position(zero index), but in another example it can be on 3rd, 4th position.
Does exist something like if <Ident> on [*] as current position == 'Capital' ? <id>[*] : ''
but not only for first but looping through all branches in xml?
thank you
Solved! Go to Solution.
07-12-2022 02:50 AM
Hi,
Try to use the below expression. It will give the Id of Ident Captial.
($Business.find(x => x.Branch.City.Ident == “Capital”)).Branch.Id
07-12-2022 02:50 AM
Hi,
Try to use the below expression. It will give the Id of Ident Captial.
($Business.find(x => x.Branch.City.Ident == “Capital”)).Branch.Id
07-12-2022 05:18 AM
It works, thank you … one more question … is it possible to use find method in scenario like this: if value matches return it (in our case value 12345) if there is no find, return number 1 ?
07-12-2022 05:35 AM
HI,
Yes, that can also possible using the below expression.
$Business.find(x => x.Branch.City.Ident == “Capital”) != null ?
($Business.find(x => x.Branch.City.Ident == “Capital”)).Branch.Id : 1
07-12-2022 10:46 PM
Thank you very much 🙂