Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Copy Nodes

Hi,

I am trying to copy nested nodes from a model node into a value node, but my subnodes are not copied anyway.

The structure that should be copied looks like

o context

|-- masternode (0..n)

|------ subnode (0..n)

|------ subnode2 (0..n)

|----


subsubnode (0..n)

they should be copied into nodes having the same structure

o

|-- newnode (0..n)

|------newsubnode (0..n)

|------newsubnode2 (0..n)

|----


subsubnode (0..n)

which means every node can contains several subnodes.

I used WDCopyService.copyElements(masternode, newnode) with the effect that all attributes were copied correctly, but all subnodes were empty.

A way I found was to copy all subnodes manually.

WDCopyService.copyElements(masternode, newnode)

WDCopyService.copyElements(masternode.subnode, newnode.newsubnode)

WDCopyService.copyElements(masternode.subnode2, newnode.newsubnode2)

But this won't copy subsubnode and I have no idea how this should work.

I tried WDCopyService.copySubtree(masternode.subnode2, newnode.newsubnode2) but the subsubnode isn't filled anyway.

Hopefully you unterstand my question and can help me out with some answers.

Thanks in advance

Fabian

Former Member
replied

When you are using copysubtree, you should check names of the subnodes.Even though the sturcture of subnodes are matching, it wont copy elemnets if the names do not match.

So your target node should have subnodes with same name as parent node.To achieve this your target node should be under different controller's context.Because you cant have two nodes with same name under same context.

Another alternative is to do it manually. Before that you need to check the singleton property of subnodes. If singleton is false, you have to iterate over elements of parent node, access subnodes from those elements and use copyelements to copy elements from parent subnode to child.

int size=wdContext.nodemasternode().size();

for(int i=0;i<size;i++)

{

IPublic<Controllername>.IMasterNodeElement element_source=

wdContext.nodemasternode().getMasterNodeElementAt(i);

IPublic<Controllername>.INewNodeElement element_target=wdContext.newNode().createNewNodeElement();

wdContext.newNode().addElement(element_target);

wdCopyService.copyCorresponding(element_source, element_target);

wdCopyService.copyElements(element_source.nodeSubNode(),

element_target.nodeNewSubNode());

wdCopyService.copyElements(element_source.nodeSubNode2(),

element_target.nodeNewSubNode2());

}

If singleton is set to true you can directly access child node and do copy elemnts.

wdCopyService.copyElements(wdContext.nodeSubNode(),

wdContext.nodeNewSubNode());

wdCopyService.copyElements(wdContext.nodeSubNode2(),

wdContext.nodeNewSubNode2());

Hope it helps.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question