Skip to Content
0

Help - UDF to loop and match same fields from 2 queus

Mar 15 at 06:31 PM

45

avatar image

Queue 1 and Queue 2 have different entries. One field is common to both queues. Requirement is to match the common field and construct the output with same number of entries as queue 1 - example below:

Please can someone suggest the way out either using node functions or UDF. Apology, my java is very poor so I need the UDF code.
-----
<Input>
<Products>
<Product>
<LineItem>10</LineItem>
<ProductID>M1</ProductID>
</Product>
<Product>
<LineItem>20</LineItem>
<ProductID>M2</ProductID>
</Product>
<Product>
<LineItem>30</LineItem>
<ProductID>M1</ProductID>
</Product>
<Product>
<LineItem>40</LineItem>
<ProductID>M2</ProductID>
</Product>
<Product>
<LineItem>50</LineItem>
<ProductID>M3</ProductID>
</Product>
</Products>
<ProductDetails>
<ProductDetail>
<ProductID>M2</ProductID>
<ProductName>M2-Name</ProductName>
<ProductWeight>M2-weight</ProductWeight>
</ProductDetail>
<ProductDetail>
<ProductID>M1</ProductID>
<ProductName>M1-Name</ProductName>
<ProductWeight>M1-weight</ProductWeight>
</ProductDetail>
<ProductDetail>
<ProductID>M3</ProductID>
<ProductName>M3-Name</ProductName>
<ProductWeight>M3-weight</ProductWeight>
</ProductDetail>
</ProductDetails>
</Input>

Expected Output:
----------------
<Output>
<ProductDetailsOut>
<ProductDetail>
<LineItem>10</LineItem>
<ProductID>M1</ProductID>
<ProductName>M1-Name</ProductName>
<ProductWeight>M1-weight</ProductWeight>
</ProductDetail>
<ProductDetail>
<LineItem>20</LineItem>
<ProductID>M2</ProductID>
<ProductName>M2-Name</ProductName>
<ProductWeight>M2-weight</ProductWeight>
</ProductDetail>
<ProductDetail>
<LineItem>30</LineItem>
<ProductID>M1</ProductID>
<ProductName>M1-Name</ProductName>
<ProductWeight>M1-weight</ProductWeight>
</ProductDetail>
<ProductDetail>
<LineItem>40</LineItem>
<ProductID>M2</ProductID>
<ProductName>M2-Name</ProductName>
<ProductWeight>M2-weight</ProductWeight>
</ProductDetail>
<ProductDetail>
<ProductID>M3</ProductID>
<LineItem>50</LineItem>
<ProductName>M3-Name</ProductName>
<ProductWeight>M3-weight</ProductWeight>
</ProductDetail>
</ProductDetailsOut>
</Output>

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Maximiliano Colman Mar 16 at 11:26 AM
1

HI,

Try with this UDF:

for(int i=0;i<var1.length;i++) {
	for(int j=0;j<var2.length;j++) {
		if(var1[i].equals(var2[j])){
			result.addValue(var3[j]);
			break;
		}
	}
}

Result:


upload.png (156.0 kB)
upload.png (184.2 kB)
Share
10 |10000 characters needed characters left characters exceeded