cancel
Showing results for 
Search instead for 
Did you mean: 

Assigning & Reading Context variable

Former Member
0 Kudos

All,

Im setting the context variable "POS_NUM" in Component controller:

wdThis.wdGetFormController().wdGetContext().getCurrentElement().setAttributeValue( "c_pos_num", pos_num);


* In View controller im reading the component controller value & passing into BAPI..
Here im getting error :Can not be converted".

  String val = wdThis.toString( wdContext.getCurrentElement().getAttributeValue( "c_pos_num") );

bapiInput.setI_Pos_Num( val );

can anyone tell me how to read the value of context variable..

BM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Bharathi,

Even more simpler:

Set values in your controller set values as:

wdContext.currentContextElement().setC_pos_num(<value>);

In view controller,

If c_pos_num value in context is of type String then simply get value using following statement:

wdContext.currentContextElement().getC_pos_num();

If it is type of int, then use following statement.

String value = new String(wdContext.currentContextElement().getC_pos_num());

Regards,

Bhavik

Former Member
0 Kudos

Thanks for the reply..

Bhavik,

But Im not getting getC_pos_num & setC_pos_num methods..

BM...

Former Member
0 Kudos

HI Bharathi,

Have you created this context attribute under root context or under any context node.

If you have created under root context then you should get setter and getter methods.

If it is available under context node then you can get by following statement:

wdcontext.current<context node>Element().getC_pos_num();

Regards,

Bhavik

Former Member
0 Kudos

Assuming that the context variable is only in component controller

Setting the value in component controller

wdContext.currentContextElement.setPOS_NUM(pos_num);

Getting the value in view controller

wdContext.wdGetComponentController.wdGetContext.getPOS_NUM();

if you map the context to view context then

Setting the value in component controller

wdContext.currentContextElement.setPOS_NUM(pos_num);

Getting the value in view controller

wdContext.currentContextElement.getPOS_NUM();

the return type depends on the 'type' of context attribute POS_NUM.

When you set it to the BAPI variable I_Pos_Num the POS_NUM value data type should be

same as I_Pos_Num.

Former Member
0 Kudos

Sorry for not giving exact detail...

Actually from InterfaceView i need to assign the value to the variable of Component controller. Could anyone tell me...

I got the answer from this forum to read variable from Componenet controller...

BM

Former Member
0 Kudos

Hi Bharathi,

First open ur the interfaceView from ComponentInterface>InterfaceViews> <WindowName>InterfaceView. Take the properties Tab and in Required Controllers, add the Component Controller using the add button provided. Then save all metadata. After this, u can assign a value from interface view to the component controller's context variable by

wdThis.wdGet<ComponentController>().wdGetContext().currentContextElement().set<attribute>("Value");

Regards

Fahad Hamsa

Former Member
0 Kudos

I will give a try & get back to you all.. Thanks a lot for tons of useful replies..

BM

Former Member
0 Kudos

Hi Bharathi,

If you want to access variable onr context attribute defined in Component controller then you have to follow this:

Create a global variable in component controller. Define it in between following section at the end of the file:

// Begin others

public String data;

// End others

Make sure, scope of this variable is public.

Now, from interfaceView, you can access value as,

wdthis.Wdget<compoent controller>().data;

Regards,

Bhavik

Former Member
0 Kudos

Nothing helpfu...

I'm setting the value in InterfaceView as follows:

	wdThis.wdGetRequisitionFormController().wdGetContext().currentContextElement().set_pos_num("125");

When I debugged the pos_num is initial here.

In Componenet controller I'm reading the value as follows:

	String value = wdContext.currentContextElement().getTemp_pos_num();

Here value is initial.

Could anyone suggest me pls.

BM

Former Member
0 Kudos

Hi Bharathi,

I guess, You have confirmed that you are checking values for Temp_pos_num after setting it from view controller.

One more check:

Right click on this context atrribute and select properties.

In properties, check whether read only property is false or not. If it is true then make it false.

Regards,

Bhavik

Former Member
0 Kudos

<i>In properties, check whether read only property is false or not. If it is true then make it false.</i>

Its already false...

Actually I'm transfering variable from one component to another component via Event parameter,

When I set the value to the target component Context variable, its not setting up..Even i hardcoded & checked also..

Pls help me..

BM

Former Member
0 Kudos

Hi Bharathi,

Have you tried printing message with this value on the screen using message manger?

Print message right after setting value in this context attributes.

It must work atleast when you have tried with hardcoding.

For, event parameter, make sure, value is passing properly or not.

regards,

Bhavik

Former Member
0 Kudos

Hi,

For cross component use server side eventing.

Go through the tutorial to cehck how you can pass values from one component to another.

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/e8d7cd90-0201-0010-4a8c-dd22fa16ca0a">Server Side eventing</a>

Answers (5)

Answers (5)

asif_hirani
Active Participant
0 Kudos

HI Bharathi

U can acess the node in the context of component controller from the interface view but before that u need to go to the properties of interface view and add the component controller as the <b>required controller</b> for the Interface view

and then u can acess the context of component controller by following line

<b>wdThis.wdGetFormController().wdGetContext().currentNodeElement().setAttributenameValue(value)</b>

Regards

Asif

former_member751941
Active Contributor
0 Kudos

Hi Bharathi,

Check the datatype of the argument of the function "setI_Pos_Num".I think it is of type "int".You are passing the value of type "String".Thats why you are getting the exception.

Try this.

try {

String val = wdThis.toString( wdContext.getCurrentElement().getAttributeValue( "c_pos_num") );

bapiInput.setI_Pos_Num(Integer.parseInt(val));

}

catch (ParseException e)

{

// TODO Auto-generated catch block

e.printStackTrace();

}

Regards,

Mithu

Former Member
0 Kudos

Hi Bharathi,

Instead of using wdThis.wdGetFormController().wdGetContext().<b>getCurrentElement()</b>.setAttributeValue( "c_pos_num", pos_num);

Use

wdThis.wdGetFormController().wdGetContext().<b>currentContextElement()</b>.setAttributeValue( "c_pos_num", pos_num);

if the variable is in the Context

OR

wdThis.wdGetFormController().wdGetContext().<b>current<Node>Element()</b>.setAttributeValue( "c_pos_num", pos_num);

if the variable is in a node

Regards

Fahad Hamsa

Former Member
0 Kudos

If u want getter and setter methods for context value attribute.u go to the particular attribute property and set "calculated" as true then u will get that methods.

former_member186016
Active Contributor
0 Kudos

Instead of

String val = wdThis.toString( wdContext.getCurrentElement().getAttributeValue( "c_pos_num") );

Do :

String val = wdContext.getCurrentElement().getAttributeAsText( "c_pos_num") ;

The way to read context attribute is correct i.e wdContext.getCurrentElement().getAttributeValue( "c_pos_num").But it returns Object.

getAttributeAsText( "c_pos_num") returns String so you need not do any casting.

Regards,

Ashwani Kr Sharma