cancel
Showing results for 
Search instead for 
Did you mean: 

Context UDF called only for first item iteration???

Former Member
0 Kudos

Hi experts,

I implemented the lookups according to the blog from Alessandro. I am using the makeArray function to build the fields array for the RT call.

In my scenario the mapping is for an order XML with several items and I have to do the lookup for each item...

<order>
...
    <item>
        <unused_field></unused_field>
        ...
    </item>
    <item>
        <unused_field></unused_field>
        ...
    </item>
…
</order>

I am triggering the lookup on an unused field.

Everything works fine for the first item, but for the second one, the function makeArray is not called???

I removed the lookup function and only kept the makeArray with a concatArray function to isolate the issue.

public void makeArray(String[] el1,String[] el2,ResultList result,Container container){
	for (int j=0;j<el1.length;j++) {
		result.addValue(el1[j]);
	}
	result.addValue(el2[0]);
}

//Concanates the values in the parameter a and add to the result
public void concatArray(String[] a,ResultList result,Container container){
	String res = "";
	for (int j=0;j<a.length;j++) {
		res = res + a[j];
	}
	result.addValue(res);
}

The mapping is the following:

[Constant1] ---> 
[Constant2] ---> makeArray() --->
               [Constant3]   ---> makeArray() ---> concatArray() ---> dest_field

The input sample XML is:

<src_order>
    <src_item>	<!—first item -->
            <src_field></src_field>
    </src_item>
    <src_item>	<!—second item -->
            <src_field></src_field>
    </src_item>
</src_order>

The result is the following:

<dest_order>
    <dest_item>
        <dest_field>Constant1Contant2Constant3</dest_field>
    </dest_item>
    <dest_item></dest_item>
</dest_order>

The second

dest_item

element is empty and does not contain the expected

dest_field

elt !!!

I have no idea why the array construction is called for the first item and is not for the next iteration…

I would really appreciate your help!

Thanks

Adalbert

Accepted Solutions (0)

Answers (1)

Answers (1)

moorthy
Active Contributor
0 Kudos

Hi,

provide the context for the root level and check the output.

Also debug based on the Queue context in the graphical editor.

hope you have used adavanced user defined function. also try to use Queue context in the user defined function

rgds,

moorthy

Former Member
0 Kudos

Thanks Krishna for your response.

I checked the Queues in the Graphic Editor. It seems there is no issues there.

The queue for dest_field elt is the following:

/dest_order/dest_item/dest_field

SUPPRESS

[Contant1Constant2Constant3]

[Contant1Constant2Constant3]

Isn’t it missing one final element is this queue?

The mapping for the dest_item is:

src_item ---> dest_item

and the queue:

/dest_order/dest_item

SUPPRESS

[]

[]

[]

The execution trace of the test mapping is:

23:35:48 Start of test

Compilation of MM_Test_MakeArray successful

Document start

Start tag [dest_order]

Start tag [dest_item]

Start tag [dest_field]

Put value [Constant1Constant2Constant3]

Close tag [dest_field]

Close tag [dest_item]

Start tag [dest_item]

Close tag [dest_item]

Close tag [dest_order]

Document end

Executed successfully

23:35:50 End of test

One “put value” is missing for the dest_item element???

What do you mean by providing the context for the root level?

I also do not understand why using UDF with Queue context as the Context should be adapted for my use. I want my function to be called at each iteration without need to access values from hierarchically higher elements.

Thanks for your help

Former Member
0 Kudos

Maybe a silly question, but maybe the target filed has occurrency =1

Regards,

Sandro

Former Member
0 Kudos

Sandro,

There is no cardinality on this element as I built the mapping from sample XMLs and not from XSDs. As default the mapping assumes that it is a 0..unbounded elt.

But the issue is not there as where I am mapping a simple constant on this field, everything works fine and the element dest_item is replicated with for each a single dest_item elt...

Adalbert

Former Member
0 Kudos

Hi,

Context type UDFs will be called for each context the input to that function has.

So you can try something like this.

Add <src_field> elt also as one more input to both ur UDFs(as third input, so that u dont need to modify ur code).

Check the UDF if they are in Context type(Just for confirmation).

So now for each context of <src_field> your UDFs will execute and u might possibly get the required output.

Regards,

P.Venkat

former_member184154
Active Contributor
0 Kudos

Try to put a CopyValue just after the MakaArray udf.

Former Member
0 Kudos

Hey Allesandro,

It works using CopyValue! Let's say it is a workaround.

But I sill do not uderstand why the fonction is only called for the first iteration.

Do you have any idea where are generated the java source classes for the mappings?

Thanks

Adalbert

Former Member
0 Kudos

Hey Allesandro,

It works using CopyValue! Let's say it is a workaround.

But I sill do not uderstand why the fonction is only called for the first iteration.

Do you have any idea where are generated the java source classes for the mappings?

Thanks

Adalbert

Former Member
0 Kudos

Hi Adalbert,

Have you tried wat i suggested in my previous post? Usually mapping "constants" don't have any contexts. So you need to map your <src_field> elt to make your UDF run for each iteration.

Regards,

P.Venkat

Former Member
0 Kudos

Hi Venkat,

I tried you suggestion and it worked for my simple test mapping, but cannot be a solution when I am building Arrays for more than 3 elements.

The mapping gets not clear and more complex.

Thanks for your help

former_member184154
Active Contributor
0 Kudos

Must be something connected to the "Cache Context" UDF feature, but don't go crazy: CopyValue does its job. Put it this way: it's just a pragmatical approach.

And don't waste time seeking for the generated Java code behind the graphical mapping. Believe me: it's very hidden!

Alex