cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Problem

0 Kudos

experts - hello

Im tryin to solve this problem. Source message look like this:

<Root>
	<Name>Mike</Name>
	<Status>Active</Status>
	<Location>
		<Country>US</Country>
		<isLocal>no</isLocal>
		<isGlobal>no</isGlobal>
	</Location>
	<Location>
		<Country>UK</Country>
		<isLocal>no</isLocal>
		<isGlobal>yes</isGlobal>
	</Location>
</Root>

And then this is logic need to be followed

if (Status = "Active")
	if (count(location) > 1) //has more than 1<Location>
		if (isGlobal = "yes")
			isGlobal is "yes"
		else
			isGlobal is "no"
		
		if (isLocal = "yes")
			isLocal is "yes"
		else if (isLocal = "no" & count(/Root/Location[isLocal = 'yes']) = "0") //there is no <isLocal> = 'yes' in all <Location>
			isLocal is "yes"
		else 
			isLocal is "no"
	else //has only 1 <Location>
		if (isGlobal = "yes" & isLocal = "no")
			isGlobal is "yes"
			isLocal is "yes"
		else if (isGlobal = "yes" & isLocal = "yes")
			isGlobal is "yes"
			isLocal is "yes"
		else if (isGlobal = "no" & isLocal = "no")
			isGlobal is "no"
			isLocal is "no"
else
	isGlobal and isLocal are both ""

Based on logic, expected output is this:

<Root>
	<Name>Mike</Name>
	<Status>Active</Status>
	<Location>
		<Country>US</Country>
		<isLocal>yes</isLocal>
		<isGlobal>no</isGlobal>
	</Location>
	<Location>
		<Country>UK</Country>
		<isLocal>yes</isLocal>
		<isGlobal>yes</isGlobal>
	</Location>
</Root>

I tried graphical mapping but the ifS only returns 1 value. Can anyone give idea how to solve? And thank you in advance!!

Accepted Solutions (0)

Answers (3)

Answers (3)

engswee
Active Contributor

Using graphical mapping would be a disaster to implement such logic. I'd suggest you look into doing it in Groovy. You can look into the following post to see how you can get started on that:-

https://blogs.sap.com/2019/06/07/i-heart-groovy-mapping/

Hi Mike,

you can put the result of one >If< element into the >than< or >else< of another. There is also the alternative to map either with Groovy (or in Java since Groovy is build on top of Java) or XSLT.

Regards

Saraj

0 Kudos

Sarah and Eng Swee - thanks to you both. I have solved using graphical and groovy.