cancel
Showing results for 
Search instead for 
Did you mean: 

How to copy data between 2 identical nodes

Former Member
0 Kudos

Hi all

does anyone know how to copy the data from one node into another node which is identical to the first node without looping through one node and adding lines for each iteration of the loop?

thanks

Anton Kruse

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Make use of



WDCopyService.copyElements(source, target)

From the doc
Copies all elements from source to target
    @param source The source node
   @param target The target node
    @throws RuntimeException if <code>target</code> is a model node and 
       source is not a model node holding the same class.

Ex:
WDCopyService.copyElements(wdContext.nodeTest(), wdContext.nodeTest1())

Regards

Ayyapparaj

Former Member
0 Kudos

Thanks I think it will work but am now getting an error saying:

cannot bind or add elements because the node has no valid parent.

any ideas what i can do to fix this?

Former Member
0 Kudos

Hi,

It seems that you are copying to a node which is a child of some other node which doesnt have a valid element.

You can make the parent node cardianlity 1..n to test

Regards

Ayyapparaj

Answers (1)

Answers (1)

Former Member
0 Kudos

hi,

I really dont understand why you need to copy the wholw node all at once.

You can easily copy it by get and set methods

suppose you have : *test1

--atr1

--atr2

and *test2

--atr1

--atr2

so now to copy valus od test1.atr1 into test2.atr1

use,

wdcontext.currentTest1Elemet.setatr1(wdcontext.currentTest2Element.getatr1);

regards,

pinki

SB9
Active Participant
0 Kudos

Pinki,

As the node element names are identical we can save writing a few lines of code by using copyElements method. Moreover this also reduces error in our code (typo errors) and makes it easier to read. Other than that the way that you have suggested is fine.

Moreover, copyElements uses reflection to copy node elements, hence it consumes more memory and is slow while copying nodes with large number of elements.

Thanks,

Soujanya