cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Logic Required

Former Member
0 Kudos

Hello,

I am trying to develop a mapping between the below source and target:

SOURCE:

<?xml version="1.0" encoding="UTF-8"?>
<test_source>
   <DOC>
      <Node>
         <status>I0001</status>
         <activ>X</activ>
      </Node>
      <Node>
         <status>I0001</status>
      </Node>
      <Node>
         <status>I0005</status>
         <activ>X</activ>
      </Node>
   </DOC>
   <DOC>
      <Node>
         <status>I0001</status>
         <activ>X</activ>
      </Node>
      <Node>
         <status>I0001</status>
      </Node>
      <Node>
         <status>I0005</status>
         <activ>X</activ>
      </Node>
   </DOC>
</test_source>

TARGET:

<?xml version="1.0" encoding="UTF-8"?>
<test_target>
	<targetnode>
		<statustype>U</statustype>
		<statustype>U</statustype>
	</targetnode>
</test_target>

Accepted Solutions (1)

Accepted Solutions (1)

PriyankaAnagani
Active Contributor
0 Kudos

Hi Pankaj,

Try this logic...

test_source--->test_target

test_source-->targetnode

status>removeContext>sort->SplitByValueChange>CollapseContext->UDF>StatusType.

UDF:

for(int i=0; i<var1.length;i++){

result.addValue("U");

}

Regards

Priyanka

Former Member
0 Kudos

Oops only part of my question got posted

Here is the condition:

1 -


> If status = I0002 AND acvtiv = X

(both the conditions evaluated separately)

2 ---> If status = I0045 AND activ = X

If 1 && 2 = true

Then statustype = A

Else statustype = U

I tried using standard functions but could not succeed.

How to solve?

Thanks

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

What could be the condition when status is other than these two values and activ is null??

Regards,

Priyanka

Former Member
0 Kudos

> What could be the condition when status is other than these two values and activ is null??

Target statustype should get the value as U; for anything where the condition does not yield A should populate U.

Thanks.

PriyankaAnagani
Active Contributor
0 Kudos

test_source--->test_target

test_source-->targetnode

UDF-->StatusType

UDF:

input1:status>removeContext>sort->SplitByValueChange>CollapseContext

input2:formatByExample-->collapseContext

sortByKey:

input1:statusremovecontext

input2:active-->removeContext

formatByExample:

input1:resultOfSortByKey

input2:tatus>removeContext>sort--->SplitByValueChange

UDF:

for(int i=0;i<var1.length;i++){

if((var1(i).equals("I0002") && var2(i).equals("X")) || (var1(i).equals("I0045") && var2(i).equals("X")))

result.addVAlue("A");

else

result.addVAlue("U");

}

Regards,

Priyanka

Former Member
0 Kudos

Hello Priyanka,

Thanks for the detailed logic. Let me check and get back with result.

Thanks.

Former Member
0 Kudos

what i have understood from ur output payload and example is that for each DOC segment u r checking condition (1&&2) and if it is true then ur statustype is "A" else "U"??

If yes then chk below mapping


status (set its context to DOC)------------\
     -------------------------------------UDF--------statustype
active---mapwithdefault                   /
                   ----------FormatByExample---
status (set its context to DOC)

UDF: input will be var1 and var2

execution type:all values of a context.



int a= var1.length;
int count = 0;
for( int i=0;i<a;i++)
{
if (var1<i>.equals("I0002") && var2<i>.equals("X"))
{
for(int j=0; j<var1.length;j++)
{
if (var1[j].equals("I0045") && var2[j].equals("X")) 
{
result.addValue("A");
count = count+ 1;
break;
}
}
}
}
if(count==0)
{
result.addValue("U");
}
 

Former Member
0 Kudos

Hello Amit,

I used your code and mapping logic, however it works only when the DOC is having one occurence.

For more occurences of DOC the target mapping fails.

I think i gave a bit wrong target structure. Below is the actual:

<?xml version="1.0" encoding="UTF-8"?>
<test_target>
	<targetnode>
		<statustype>U</statustype> ..1..1
	</targetnode>
	<targetnode>
		<statustype>U</statustype>1..1
	</targetnode>

</test_target>

Can you please help?

Thanks.

Former Member
0 Kudos

use below mapping and let me know if this works or not...

mapping-UDFremoveContext---targetnode

mapping-UDF--statustype

Former Member
0 Kudos

Hello Amit,

It does not work

I have also tried mapping DOC -> targetnode (for occurence)

But the real problem is getting the statustype occurences from second instances.

Former Member
0 Kudos

it seems bit strange because i have tested the mapping with the input source payload which u have provided and it's resulting the expected output...

use the display queue option and chk whats the UDF output is coming in the mapping

give a try with splitbyvalue

mapping-UDFsplitbyvalue--statustype

Answers (0)