Forum Discussion

SL12345's avatar
SL12345
New Contributor III
3 years ago
Solved

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

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

  • 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

4 Replies

  • 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's avatar
      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 ?

  • 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