cancel
Showing results for 
Search instead for 
Did you mean: 

Copy value node to model node

Former Member
0 Kudos

Hi SDN,

I need copy value node to model node. How create the instace of model node, for copy this value node.

This model node is an import table of R3.

Thank's

Accepted Solutions (0)

Answers (7)

Answers (7)

monalisa_biswal
Contributor
0 Kudos

Copyingd data from value node to model node is not possible because model node holds reference whose information is not there in value node.

What u can do

1>u can iterate over value node.

2>Get the reference of parent model node.

3>Add objects of child model node to the parent model node.

4>Copy values using copy corresponding method.

<Parent Model Node's class> input =

wdContext.current<Parent Model Node>element().modelObject();

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

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

{

IWDNode el=wdContext.node<value node>().getElementAt(i);

input.add<ChildNode>(new <ChildNodeModelClass>());

wdContext.node<ChildNode>.moveLast();

wdCopyservice.copyCorresponding(el,wdContext.current<ChildModelNode>);

}

Former Member
0 Kudos

Hi,

If you want to copy value node to model node then loop through the value node and set the corresponding values to model node.

use the following code:

IPublic/Private<Comp/view>.I<ModelNode>Element e1;

for (int i = 0; i < wdContext.node< ValueNode>.size(); i++) {

// Create the model/structure instance

Zsd_Pmt_S_Prodgrd elem = new Zsd_Pmt_S_Prodgrd(); (for example)

// set the values

elem.set<attribute1>(wdContext.node<ValueNode>()

.get<ValueNode>ElementAt(i).get<Element>());

elem.set<attribute2> (wdContext.node<ValueNode>()

.get<ValueNode>ElementAt(i).get<Element>());

e1 = wdContext.node<ModelNode>().create<ModelNode>Element(elem);

wdContext.node<ModelNode>().addElement(e1);

}

Regards,

Jhansi

The method WDCopyService.copyElements copies only those attributes from "source" which are present in "target" and if they match (the names equal case-sensitive and the types are compatible).Please check if your contexts nodes have the same sets of attributes. And <b>WDCopyService cannot copy the value node to model node</b>.It is used when you want to copy model node to value node.

Former Member
0 Kudos

Hi,

if it's not created you should first bind the model node before filling:

 wdContext.nodeModelNode().bind(new Model);

after that, you can iterate over that value table.

You can also try to use the wdCopyService. But I think especially for tables

it's more secure to iterate over the table.

Sometimes the copied values are not passed to the R3 System.

regards

Former Member
0 Kudos

Hi,

The node value have same structure of model node.

But when i copy value node to model node A, this not created.

The instance is not careated, and return error.

.value node

.Model node

-> A

abhijeet_mukkawar
Active Contributor
0 Kudos

hi,

WdCopyservice i guess is used for model to value , i misunderstood the post , sorry.

for value to model i suppose iterating through node is the only way since model node has some reference while value node doesnt

refer this

hope it helps

regards,

Message was edited by:

abhijeet mukkawar

Former Member
0 Kudos

Hi,

If the Elements doesn't have the same type you can just doing a loop over your table:


wdContext.nodeModelTable().invalidate();

for(int i = 0;i < wdContext.nodeValueNode().size();i++){
		IPublicComponent.IModelTableElement element = wdContext.createModelTableElement(new ModelTableType);
		wdContext.nodeModelTable().addElement(element);

		element.setAttribute1(wdContext.nodeValueNode().getElementAt(i).getAttributeValue("Attribute1").toString());	
		element.setAttribure2(wdContext.nodeValueNode().getElementAt(i).getAttributeValue("Attribute1").toString());
                ..................		
		
	} 	

Best regards,

Dennis

abhijeet_mukkawar
Active Contributor
0 Kudos

if both the node have same structure you can use,

WDCopyService.copySubtree((IWDNode)ModelNode,(IWDNode)ValueNode);

for them having different structure , you gotta code like, in iterative manner

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();

<complete path>.<ModelNode> so = (<complete path like com.sap...>.<ModelNode>)lst.get(i);

sData.setAttributeOne(so.getAttributeOne());

sData.setAttributeTwo(so.getAttributeTwo());

sData.setAttributeThree(so.getAttributeThree());

newList.add(sData);

}

wdContext.node<name>().bind(newList);

hope it helps

regards

Message was edited by:

abhijeet mukkawar

Message was edited by:

abhijeet mukkawar

Message was edited by:

abhijeet mukkawar

Abhinav_Sharma
Contributor
0 Kudos

Hi David,

you can create the instance of the model node. The variou classes are shown under Models -> <ur model Name> -> Model Classes There you can find the modle nodes that you can instantiated.

you can copy ur value node to model node as:

<ModelNode> model = new <ModelNode>();

wdContext.node<ModelNode>().bind(model);

model.set<attributenname>(valueElement.get<attributename>);

<b>Do rewards point if it helps.</b>

Abhinav Sharma