Skip to Content
avatar image
Former Member

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

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>

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Mar 16 at 11:26 AM

    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:

    Add comment
    10|10000 characters needed characters exceeded