cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically create a model node

Former Member
0 Kudos

Hello,

I have the following Model node structure in my custom controller.

Zhr_Employee_Details_Input (Model Node)

-


Output (Model Node)

-


T_Org_Ass (Model Node)

-


Pernr (Model Attribute)

-


I_Pernr (Model Attribute)

Now I need to dynimacally create a Zhr_Employee_Details_Input node and populate I_Pernr.

I am using below code to achieve the task.

IPublicLetterHCMCust.IZhr_Employee_Details_InputElement inputElement = wdContext.createZhr_Employee_Details_InputElement(new Zhr_Employee_Details_Input());
			   
	   inputElement.setI_Pernr("String Value");		
		 try {
			inputElement.modelObject().execute();
			inputElement.node().getChildNode("Output",0).invalidate();
		
		 }
		 catch(Exception e){
		
		 }

I am getting a null pointer exception in

inputElement.node().getChildNode("Output",0).invalidate();

I feel I am not able to properly create the model node.

Please help me out of this.

Accepted Solutions (1)

Accepted Solutions (1)

Qualiture
Active Contributor
0 Kudos

Hi,

You have to add the created element to your node too.

I.e.

inputElement.node().addElement(inputElement);

See also API http://help.sap.com/javadocs/NW04S/SPS09/wd/com/sap/tc/webdynpro/progmodel/api/IWDNode.html#createEl...

Creates a new node element of the type used for this model node.

The element is not yet inserted in the node collection, its IWDNodeElement.node() method will return null.

Hope this explains!

Best regards,

Robin van het Hof

Former Member
0 Kudos

Hello Robin,

I added below code :

inputElement.node().addElement(inputElement);

right after

inputElement.setI_Pernr(ovsInput_VN.getPersonalNo());

but it is giving null at

inputElement.node()

!!

Qualiture
Active Contributor
0 Kudos

Hi Saurabh,

I believe you first have to add the element to the node collection before setting its attribute values.

Could you try the following:

IWDNode inputNode = wdContext.nodeZhr_Employee_Details_Input();
IPublicLetterHCMCust.IZhr_Employee_Details_InputElement inputElement = wdContext.createZhr_Employee_Details_InputElement(new Zhr_Employee_Details_Input());

inputNode.addElement(inputElement);

inputElement.setI_Pernr("String Value");
//etc

Former Member
0 Kudos

Hello

The modification in code I did is :

wdContext.nodeZhr_Employee_Details_Input().addElement(inputElement);

Actually this whole structure of model node in my question is mapped context structure from RFC model.

The T_Org_Ass is output node in this structure.

Using above code I am now able to successfully sent input RFC.

But output is not getting in T_Org_Ass.

Because when I try below code snippet

int i = wdContext.nodeT_Org_Ass().size();

it is returning 0 as value of i.

I feel while initializing as below code:

IPublicLetterHCMCust.IZhr_Employee_Details_InputElement inputElement = wdContext.createZhr_Employee_Details_InputElement(new Zhr_Employee_Details_Input());
			   
	   
	   wdContext.nodeZhr_Employee_Details_Input().addElement(inputElement);
	   inputElement.setI_Pernr(ovsInput_VN.getPersonalNo());

I am not able to initialize T_Org_Ass.

Please comment as the way I am initializing the context structure is not proper.

All its child nodes are not getting in intialized.....

Qualiture
Active Contributor
0 Kudos

That is true, for each child node you need to populate them in the same manner

Former Member
0 Kudos

Thanks Robin,

Just last suggestion...then I will start developing it....

Do I need to create separate element for Output node.

Or do I need to create separate element for T_Org_Ass node.

After making these elements similarly how will I bind them to parent node i.e. Zhr_Employee_Details_Input....

Qualiture
Active Contributor
0 Kudos

Hi,

From what I can deduct from your context, you'll need to add an element for T_Org_Ass only.

Former Member
0 Kudos

Hello

I have added below code to create the T_Org_Ass element in my context structure.

IPublicLetterHCMCust.IT_Org_AssElement orgElement = wdContext.createT_Org_AssElement(new Zlt_Pa0001());

wdContext.nodeT_Org_Ass().addElement(orgElement);

But while executing it is throwing following error :

Node(LetterHCMCust.Zhr_Employee_Details_Input.Output.T_Org_Ass): cannot bind or add elements because the node has no valid parent

I think I need to bind it to parent.

But I am not able to find any such function to bind parent to child in either parent or child context.

Qualiture
Active Contributor
0 Kudos

Can you try adding an element for the parent as well?

Remember, binding is only done between contexts of controllers, interfaces, views, etc. Parent-child relationships cannot be bound.

Former Member
0 Kudos

Hello Robin,

Thanks for all support,

Below code snippet did it for me.....finally

Zhr_Employee_Details_Input inputElement = new Zhr_Employee_Details_Input();
	   inputElement.setI_Pernr(ovsInput_VN.getPersonalNo());
	   inputElement.addT_Org_Ass(new Zlt_Pa0001());

Answers (0)