cancel
Showing results for 
Search instead for 
Did you mean: 

graphical mapping of tables on the same level

Former Member
0 Kudos

Hi,

I have a problem of mapping of XML similar to this:

<ns0:Items> (0..1)

<ns0:SimpleSale> (0..unbounded)

<ns0:ItemCode>0000931927</ns0:ItemCode>

<ns0:PlanningGroup>0718</ns0:PlanningGroup>

<ns0:SubPlanningGroup>7180</ns0:SubPlanningGroup>

<ns0:Quantity>1</ns0:Quantity>

<ns0:TotalSellingPrice>1299.99</ns0:TotalSellingPrice>

<ns0:PriceOverridden>false</ns0:PriceOverridden>

<ns0:Scanned>false</ns0:Scanned>

<ns0:CommissionEarner>1010101</ns0:CommissionEarner>

<ns0:AssistantID>1</ns0:AssistantID>

<ns0:Discount> (0..unbounded)

<ns0:Amount>-104.01</ns0:Amount>

<ns0:ReasonCode>AA</ns0:ReasonCode>

</ns0:Discount>

<ns0:Discount> (0..unbounded)

<ns0:Amount>-104.02</ns0:Amount>

<ns0:ReasonCode>BB</ns0:ReasonCode>

</ns0:Discount>

<ns0:DCOutfitOrderInfo> (0..1)

<ns0:Component> (0..unbounded)

<ns0:DistributionCentre>7422</ns0:DistributionCentre>

<ns0:ItemCode>0000747861</ns0:ItemCode>

<ns0:StockSource>B</ns0:StockSource>

</ns0:Component>

<ns0:Component> (0..unbounded)

<ns0:DistributionCentre>7422</ns0:DistributionCentre>

<ns0:ItemCode>0000925193</ns0:ItemCode>

<ns0:StockSource>L</ns0:StockSource>

<ns0:SaltNumber>2208340261</ns0:SaltNumber>

</ns0:Component>

</ns0:DCOutfitOrderInfo>

</ns0:SimpleSale>

</ns0:Items>

and I need to map it like this:

<ns0:Items> (0..unbounded)

<ns0:DistributionCentre>7422</ns0:DistributionCentre>

<ns0:ItemCode>0000747861</ns0:ItemCode>

<ns0:StockSource>B</ns0:StockSource>

<ns0:Discount> (0..unbounded)

<ns0:Amount>-104.01</ns0:Amount>

<ns0:ReasonCode>AA</ns0:ReasonCode>

</ns0:Discount>

<ns0:Discount> (0..unbounded)

<ns0:Amount>-104.02</ns0:Amount>

<ns0:ReasonCode>BB</ns0:ReasonCode>

</ns0:Discount>

</ns0:Items>

<ns0:Items> (0..unbounded)

<ns0:DistributionCentre>7422</ns0:DistributionCentre>

<ns0:ItemCode>0000925193</ns0:ItemCode>

<ns0:StockSource>L</ns0:StockSource>

<ns0:Discount> (0..unbounded)

<ns0:Amount>-104.01</ns0:Amount>

<ns0:ReasonCode>AA</ns0:ReasonCode>

</ns0:Discount>

<ns0:Discount> (0..unbounded)

<ns0:Amount>-104.02</ns0:Amount>

<ns0:ReasonCode>BB</ns0:ReasonCode>

</ns0:Discount>

</ns0:Items>

I changed context of <ns0:Component> to Items and mapped it to target <ns0:Items>. It's working fine. But I need to create 2 discount records for every component (target Item) record - I need to copy all discount records for every component.

I tried to use function UseOneAsMany in mapping of fileds <ns0:Discount> ---> <ns0:Discount> with parameters inp1: <ns0:Discount>; inp2: <ns0:ItemCode> (context changed to <ns0:SimpleSale>); inp3: <ns0:ItemCode>...

But there is compilation error which says, that there are too many values in first queue... The problem is, that I need to use the whole "discount" node and use it for every component (Item code). Is it possible to make it in graphical mapping?

I'll be happy for any help.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sarvesh,

No, I need to create all discount records for each component item. So if I have 3 discount records and 2 component records in the source XML, I need to have it like this:

1. Item rec. (created from the 1. component rec.)

_1. discount rec.

_ 2. discount rec.

_ 3. discount rec.

2. Item rec. (created from the 2. component rec.)

_ 1. discount rec.

_ 2. discount rec.

_ 3. discount rec.

So I need to map <discount> -


> <discount>, but when I use <discount> -


> RemoveContext -


> <discount> mapping, there are discount items only for the first Item rec. created and not for the second, so the target XML look like this:

1. Item rec. (created from the 1. component rec.)

_1. discount rec.

_ 2. discount rec.

_ 3. discount rec.

2. Item rec. (created from the 2. component rec.)

I can't use <component> (change context to Items) -


> <discount>, because I need to create all discount records for every component and not the only one (or as many as number of component records) ...

I think, that I need to use UseOneAsMany, but I need to use all 3 discount records (in our case) for each component to Item mapping. But it does't work if there is more then 1 discount record in source XML...

former_member518917
Participant
0 Kudos

Hi,

you can achieve this by writing UDF.

// Cache type of UDF is "CONTEXT"

//two Input parameters:

//*** mapping to target DISCOUNT : input parameters are (1) Discount (2) Component (both in defauult context)

//*** mapping to subfields of DISCOUNT say Amount : input parameters are (1) Amount ( Context "SimpleSale" ) (2) Component (in default context)

//public void createNode(String[] a,String[] b,ResultList result,Container container){

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

for(int j=0;j<a.length;j++){

result.addValue(a[j]);

}

if(i!=b.length-1){

result.addValue(ResultList.CC);

}

}

Regards

Ritu

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi, Thanks a lot for your posts. I tried that UDF and it's working fine in most cases. But I have one case, when it's not working.

If you have 3 simple sale records. The first one has 2 discounts and 2 components. The second has no discount record and 2 components. The third one has 2 discount records and 2 components.

The expected result is.

Component 1

- discount 1

- discount 1

Component 2

- discount 2

- discount 2

Component 3

Component 4

Component 5

- discount 3

- discount 4

Component 6

- discount 3

- discount 4

But when I use that UDF, there are 2 SUPPRESS records in out queue, which I need to remove. Do you know, how to remove these SUPPRESS record from resultlist?

Thanks for help.

Former Member
0 Kudos

Hi Ritu,

Thanks for your reply. I'll try your UDF and let you know...

Former Member
0 Kudos

Hi,

I have create the desired mapping in my system and tested it and found satisfactroy results. Go through these screen shots and see if it is going to solve your problem. If yes then do not forget to say thanks to Ritu Sinha for her UDF, because I have used her UDF in my mapping. So here we go.....

Expected Result

http://www.flickr.com/photos/23639237@N02/2902161764/

Source & Target Structure & their occurrences

http://www.flickr.com/photos/23639237@N02/2901325659/

Mapping Rules and UDF code by Ritu Sinha

http://www.flickr.com/photos/23639237@N02/2902171024/

I hope this effort will be useful for you.

Regards,

Sarvesh

Former Member
0 Kudos

Hi,

I tried your sollution for root node mapping, but it creates discount records only for the first component (target Item) and not for the second, third ... etc. I need to use the whole "source discount table" as many times as I use source component record table. So I think, that I need to use UseOneAsMany...

Or am I doing something wrong?

Former Member
0 Kudos

oho.. you need to map the Component instead of Discount to create the Root node because you want Discount should occur for each and every occourance of componet in each items.

Component (Change then Context to Items) -


> Discount.

Former Member
0 Kudos

Hi,

Thanks for your reply. I know that blog. But my problem is quite different. The main problem is mapping between root discount nodes, because for every component record, I need to create whole set of discount records. It's not only about replication of single field. And my question is - is it possible?

When I map <discount> ---> <discount>

UseOneAsMany:

inp1: <Discount>

inp2: <Component> (context changed to SimpleSale)

inp3: <ItemCode>

then it's all looking fine until there's only one discount record. When there are more than one source discount redords, it thows that exception described last time...

Former Member
0 Kudos

If I have got you correctly then...

For mapping the root Discount node you need not to use the UseOneAsMany function, map like this..

Discount -


>RemoveContext -


> Discount.

And for rest of the fields inside the Discount you have to map as I have explained in my earlier reply.

Former Member
0 Kudos

Hi again,

Map your fields to UseOneAsMany function like this...

input1: Amount

input2: Component (Change the Context to Item)

input3: Component (Do not change the context)

Similarly

input1: ReasonCode

input2: Component (Change the Context to Item)

input3: Component (Do not change the context)

I hope this will help you.

Regards,

Sarvesh

Former Member
0 Kudos

Hi

Well, the way you have used UseOneAsmany is seems incorrect, so plz gothrough this blog and then map your fields accordingly.

Just in short, in UseOneAsMany function in the first input map the source field and in the other two input you nedd to map the filed for which (or as may times this field occours) you need to map the source field.

Note: while using UseOneAsMany function, context is very important.

Replication of Nodes Using the Graphical Mapping Tool (UseOneAsMany)

Regards,

Sarvesh