cancel
Showing results for 
Search instead for 
Did you mean: 

Grouping of Source Data based on Common Values

former_member192105
Participant

Hello,

I have a File to File scenario and have a mapping requirement between below shown Source and Target structures:

The Employee IDs in the source structure should be grouped together as per their Departments in the Target structure.

Any idea on how this can be achieved in message mapping?

Thank you!

Accepted Solutions (1)

Accepted Solutions (1)

manoj_khavatkopp
Active Contributor

Try the below :

Mapping:

Output:

UDF -AddArray: ( All values of a context)

String out= String.join(",", var1); 
result.addValue(out);

Br,

Manoj

former_member192105
Participant
0 Kudos

Dear Manoj,

The mapping logic is working perfectly as expected.

Thank you!

Answers (2)

Answers (2)

hasan_celebi
Participant

Hi Abhishek;

You can use this mapping.

Item


Emp_ID



Department

concatContextValues UDF

if (delimiterString == null || delimiterString.length == 0) {

throw new IllegalStateException("concatContextValues: "

+ "there is no delimiterString");

}

if (contextValues != null && contextValues.length > 0) {

String delimiter = delimiterString[0];

StringBuffer sb = new StringBuffer(contextValues[0]);

for (int i = 1; i < contextValues.length; i++) {

sb.append(delimiter).append(contextValues[i]);

}

result.addValue(sb.toString());

}


Test Result

Regards
Hasan

former_member192105
Participant
0 Kudos

Dear Hasan,

Thank you for your response!

apu_das2
Active Contributor
0 Kudos

Use multiple mapping.

1) In the first MM - use format by example so that you can get data like below -

<Item>

<Emp_ID> 1111 </Emp_ID>

<Emp_ID> 2222 </Emp_ID>

<Department> Sales </Department>

</Item>

<Item>

<Emp_ID> 4444 </Emp_ID>

<Emp_ID> 6666</Emp_ID>

<Emp_ID> 9999</Emp_ID>

<Department> Accounting</Department>

</Item>

2) In the second MM, Write a simple UDF to concat EMP_ID values separated by coma and put into the final structure.

Thanks,

Apu

former_member192105
Participant
0 Kudos

Dear Apu,

Thank you for your response!