cancel
Showing results for 
Search instead for 
Did you mean: 

XML - How to get value from actual position based on another value

SL12345
New Contributor III

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

1 ACCEPTED SOLUTION

nsingam
Employee
Employee

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

View solution in original post

4 REPLIES 4

nsingam
Employee
Employee

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

SL12345
New Contributor III

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 ?

nsingam
Employee
Employee

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

SL12345
New Contributor III

Thank you very much 🙂