cancel
Showing results for 
Search instead for 
Did you mean: 

How to copy node elements from one to another ?

Former Member
0 Kudos

Hi all,

I'd like to copy values from one node to another. Both sublying models are similar, but different types (one is bapitrvreo type and the other is ptrv_receipts).

However, most of the fields are the same (same name and same type).

I've found out this interesting method copyCorresponding, from WDCopyService class, but I don't understand how can I use it...

Here is a piece of my code that is working, but not really good:

Ptrv_Receipts receipt = new Ptrv_Receipts();
receipt.setExp_Type(wdContext.currentReceiptsElement().modelObject().getExp_Type());
receipt.setRec_Amount(wdContext.currentReceiptsElement().modelObject().getRec_Amount());
receipt.setRec_Curr(wdContext.currentReceiptsElement().modelObject().getRec_Curr());
receipt.setRec_Date(wdContext.currentReceiptsElement().modelObject().getRec_Date());
receipt.setRec_Refnr(wdContext.currentReceiptsElement().modelObject().getRec_Refnr());
receipt.setRec_Rate(wdContext.currentReceiptsElement().modelObject().getRec_Rate());
receipt.setShorttxt(wdContext.currentReceiptsElement().modelObject().getShorttxt());

And here is what I'd like to do, if possible:

Ptrv_Receipts receipt = new Ptrv_Receipts();
WDCopyService.copyCorresponding(receipt, wdContext.currentReceiptsElement().modelObject());

Thanks for any help,

Caroline

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi

u can usae wdCopy Service Method but the node u r copyin to shuld contain the same structure of the Source Node.

please check that

The Source Node and destination Node shuld contain the same no of Value Attributes.

The Value Attributes Names shuld also be the same

Here is following Example

WDCopyService.copyElements(wdContext.node<<Source>>(),wdContext.node<<Dest>>);

Hope this shuld help u

With Wishes

Krishna kanth

Message was edited by: krish kanth

Former Member
0 Kudos

Thanks to both of you for your anwers...

If I understand well, you mean that it's not possible to use copyservice to copy one node to another if I have the following structure:

node1

- attr1

- attr2

- attr4

node2

- attr1

- attr3

- attr4

I thought WDCopyService would be able to copy matching attributes from one node to the other (kind of reflexion system).

Do you have any advice on how to do such a copy in that case ?

Former Member
0 Kudos

This is kind of joke, but anyway this should work:

create mapping with the following structure:


node1_mapped
- attr1
- attr2
- attr3 (unmapped)
- attr4

node2_mapped
- attr1
- attr2 (unmapped)
- attr3
- attr4

Then use WDCopyService over mapped nodes

VS

Former Member
0 Kudos

Thanks Valery

Unfortunately, I can't do this, as my model nodes are dictionary structure binding

Should I do mapping hard-coded ? I would definitively have prefered some more beautiful way

Former Member
0 Kudos

Ok, but did you try approach you were suggesting yourself: just use WDCopyService over model objects. From documentation it seems that copying always applied for matching attributes and others are ignored. Do you recieve exceptions of some kind?

VS

Former Member
0 Kudos

Well, I tried... The reason why I posted a message is that the result of the copy is an empty element, for some reason...

Former Member
0 Kudos

From documentation:<i>

The method inspects all attributes of source, searches a compatible attribute in target and copies the value if it finds one. Values are considered compatible if their Java class matches:

- All numeric classes (Byte, Short, Integer, Long, Float, Double, BigInteger and BigDecimal) and primitives (byte, short, int, long, float, double) are compatible.

- Boolean class and primitive are compatible.

- Character (class) and char (primitive) are compatible.

- Otherwise source and target attribute must be based on the same class.</i>

So, as far as I understand, your model attributes have the same name but brokes type compatibility?

VS

Former Member
0 Kudos

OK, it works... I was not looking at the correct node

emmanuel_turci
Advisor
Advisor
0 Kudos

Hi Caroline,

Everything is done for you in the class you just mentionned (WDCopyService), just check how to use it in the hehp within your IDE...

Otherwise for quick help:

// this code copy one element into another one with all attributes of course.

// the newElementInserted has to be an existing element of course.

WDCopyService.copyCorresponding(elementFrom,newElementInserted);

// you can use also this beautifull class, this one use sub folder copy and copy all sub nodes

WDCopyService.copySubtree()

I hope it will help you

Best regards,

Emmanuel.