cancel
Showing results for 
Search instead for 
Did you mean: 

How manually accessing Value Attributes from a Context ?

Former Member
0 Kudos

Hi,

I have some problems in understanding how to access "Value Attributes" from a context.

I like to read some data manually within a method in the custom controller class.

my context looks like this:

Context:

|- Request_xyz (=Model node)

..|- Response (=Model node)

....|- Result (=Model node)

.......- city (=Value Attribute)

.......- country (=Value Attribute)

(... are used as spaces, only for formatting the context for the forum)

But how can I now read/access the string data/values from "city" and "country"? They are filled with data from a webservice.

Thanks a lot for your help.

Best regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos
IResultElement result = wdContext.currentResultElement();
if (result != null)
{
  result.getCity(); /* get value of attribute */
  result.setCity("St. Ingbert"); /* set value of attribute */ 
}

Armin

Former Member
0 Kudos

Hi Armin,

thanks for the code. This solution works fine for me.

Henning

Answers (6)

Answers (6)

monalisa_biswal
Contributor
0 Kudos

Before accessing any value for Result Node Check whether it has some elements or not.

Since it contains single element as u mentioned u can access that element using wdContext.current<node>element().get<attribute>()

if(wdContext.nodeResult()!=null&&wdContext.nodeResult().size()>0)

{

wdComponentAPI.getMessageManager.

reportSuccess(wdContext.currentResultElement().getCity());

}

Hope it helps.

Former Member
0 Kudos

I just tried some ways to receive the value:

This works fine for me:

String city = wdContext.nodeResult().getElementAt(0).getAttributeValue("cITY").toString();

ok, the "0" is hardcoded what is not the best way.

Henning

lajitha_menon
Contributor
0 Kudos

Hi Henning,

As you said, because the 0 is hardcoded in your code, it works fine as long as the wsdl returns atleast one element in the result node. This code will throw a nullPointerException if the result node is empty..So, you would have to consider that situation to be sure that your code works ok in all conditions,

Regards

LM

Former Member
0 Kudos

Hi,

Try this,

IWDMessageManager msg = wdComponentAPI.getMessageManager();

for(int i = 0; i<wdContext.nodeResult().size(); i++){

msg.reportSuccess("City: "+wdcontext.nodeResult().getResultElementAt(i).getCity());

msg.reportSuccess("Country: "+wdcontext.nodeResult().getResultElementAt(i).getCountry());

}

Regards,

Aparna .P

Former Member
0 Kudos
lajitha_menon
Contributor
0 Kudos

Hi there,

I assume the actual context if you are executing a web service would look like this

RootContext

|.|WebserviceRootNode

..|- Request_xyz (=Model node)

..|- Response (=Model node)

....|- Result (=Model node)

.......- city (=Value Attribute)

.......- country (=Value Attribute)

Now after executing the webservice, you need to invalidate the output nodes to get the data to the nodes-like this

wdContext.nodeResponse().invalidate();

wdContext.nodeResult().invalidate();

Then you can access context nodes like this

for(int i=0;i<wdContext.nodeResult().size();i++){
wdContext.nodeResult().setLeadSelection(i);
wdComponentAPI.getMessageManager().reportSuccess(wdContext.currentResultElement().getCity());

}

Former Member
0 Kudos

Hi,

thanks for your tips. I will try it tomorrow when I have access to my SAP system.

>

> Then you can access context nodes like this

> for(int

> i=0;i<wdContext.nodeResult().size();i++){

> wdContext.nodeResult().setLeadSelection(i);

> wdComponentAPI.getMessageManager().reportSuccess(wdCon

> text.currentResultElement().getCity());

>

ok, sounds good. But this loop doesn't assign the "city"-value attribute-string to a single string-variable, or does it? How can I archieve this?

The webservice only sends back single string-results, no table with several entries.

Thx.

Henning

Former Member
0 Kudos

Henning,

you can do the following.

Considering only one record in result node

String city = wdContext.currentResultElement().getCity();

String country = wdContext.currentResultElement().getCountry();

if you have more than one rows of result then you need to loop through the Result node.

Note: Use this code to access the data only after the web service is executed otherwise you will get NullPointer exception.

I hope this will help you.

Regards,

Anand