cancel
Showing results for 
Search instead for 
Did you mean: 

copy model node to value node

Former Member
0 Kudos

i have a table ....which i populate my table with the model node....

when i put this code i get an incompatible node exception

wdContext.currentContextElement().getTableFilter().filter(wdEvent,wdContext.nodeProductCommandBean wdContext.nodeProduct(),wdContext.nodeVnFilters());

copy model node to value node will result in incompatible node...

wat is the solution for this....

for instance when using table filter


wdContext.currentContextElement().getTableFilter().filter(wdEvent,wdContext.nodeProductCommandBean wdContext.nodeProduct(),wdContext.nodeVnFilters());

Message was edited by:

yzme yzme

Accepted Solutions (1)

Accepted Solutions (1)

ashutosh_rastogi
Active Contributor
0 Kudos

Hi,

I Have faced the similar situation before, where i have to copy some of the model node values to value node structure. And since both structures are different you cannot use the copy service.

What you can code is loop over the model node , fetch the values ...then create the value node elements and keep addign them to a java.util.List. And at last bind that list to your value node.

Code Should Look Like this



java.util.List lst = wdContext.current<ModelNode>Element().modelObject().get<Model>Response_Sync().get<ListOfElements>(); 
	  java.util.List newList =  new java.util.ArrayList();   
  
	  IPublic<Component>.I<ValueNode>Element sData = null; 	  
  
	  for (int i =0; i < lst.size(); i++){
		sData = wdContext.create<ValueNode>Element(); 
  	
		com.sap.model.so007qr.<ModelNode> so = (com.sap.model.so007qr.<ModelNode>)lst.get(i);
		
			sData.setAttributeOne(so.getAttributeOne());
			sData.setAttributeTwo(so.getAttributeTwo());
			sData.setAttributeThree(so.getAttributeThree());

		newList.add(sData);
	  }
  	    
	  wdContext.nodeSalesData().bind(newList);

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

I'm doing that with:


//IT WORKS
WDCopyService.copySubtree((IWDNode)ModelNode,(IWDNode)ValueNode);

It works fine but it doesn't work in the reverse manner:


//IT DOESN'T WORK
WDCopyService.copySubtree((IWDNode)ValueNode,(IWDNode)ModelNode);

Former Member
0 Kudos

actually i am iterating the node

int size = wdContext.node<modelnodename>.size();

IPrivate<viewname>.I<Valuenodename>Element ele;

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

{

ele = wdContext.create<valuenodename>element();

ele.setname(wdContext.node<modelnodename>.get<modelnodename>elementat(i).getname();

ele.setPrive(wdContext.node<modelnodename>.get<modelnodename>elementat(i).getprice();

wdContext.node<valuenodename>.addelement(ele);

}

though copysubtree is a good idea..i will try...

monalisa_biswal
Contributor
0 Kudos

Can u explain what is the exact error you are getting ?

Copying data from model node to value node will not cause any error if they share same structure.

Former Member
0 Kudos

It is sample structure...

modelnode

- name

-price

valuenode

-name

-price

Exception : Incompatible Node

Former Member
0 Kudos

hi,

try out this.

int size = wdContext.node<modelnodename>.size();

IPrivate<viewname>.I<Valuenodename>Element ele;

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

{

ele = wdContext.create<valuenodename>element();

ele.setname(wdContext.node<modelnodename>.get<modelnodename>elementat(i).getname();

ele.setPrive(wdContext.node<modelnodename>.get<modelnodename>elementat(i).getprice();

wdContext.node<valuenodename>.addelement(ele);

}

Try out this code.

Regards,

Gopi

Former Member
0 Kudos

Hi,

If both the model and value node are of the same structure. Then you can use

WDCopyService.copy........();

function to transfer the data in one shot.

Regards,

Mahesh

Former Member
0 Kudos

please, describe in more details: what do you mean "copy model node to value node", and "incompatible node".

clear question is half of an answer