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 ๐Ÿ™‚