cancel
Showing results for 
Search instead for 
Did you mean: 

How do you loop nested nodes from a web service call?

Former Member
0 Kudos

Hi Experts,

I'm stuck in trying to access data from a web service call made with an Adaptive Web Service model.

Here is what the model context looks like, I'll put the cardinality next to each one.



Root
   Request_SearchQuery (0..n)
      Response (0..1)
         SearchQueryReturn (0..1)
            Record (0..n)
               Record1 (1..1)
                  Field (0..n)
                     Field1 (0..1)
                        stringValue (valuedata; contains data pertaining to field name)
                  stringName (metadata; contains field name)
      SearchQuery (0..1)

SearchQuery (0..1) takes the initial values to execute the query.

Record (0..n) contains how many rows in the table

Field (0..n) contains how many fields in a row

stringName is the name of the field (ie table column name)

stringValue is the data value for the particular field.

I am having severe trouble looping the fields and records as I do not know what methods to use out of the web dynpro API.

I need to loop through all fields in one record (table row) and then move to the next record and loop all the fields etc. The weird thing is the webservice returns the field name under node Field, and the field value under node Field1.

Please help.

M

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

To answer your question, I need to know the value of the "singleton"-property for all context nodes.

Armin

Former Member
0 Kudos

Hi Armin,

Please see below, the Singleton property value is added right after the cardinality.


Root
   Request_SearchQuery (0..n) (true)
      Response (0..1) (true)
         SearchQueryReturn (0..1) (true)
            Record (0..n) (true)
               Record1 (1..1) (true)
                  Field (0..n) (true)
                     Field1 (0..1) (true)
                        stringValue (valuedata; contains data pertaining to field name)
                  stringName (metadata; contains field name)
      SearchQuery (0..1)

These are all model nodes bound to the web service model.

Thanks

Marshall.

Former Member
0 Kudos

Try


for (int i = 0; i < wdContext.nodeRecord().size(); ++i)
{
  IRecordElement r = wdContext.nodeRecord().getRecordElementAt(i);
  wdContext.nodeRecord().moveTo(i);
  for (int j = 0; i < wdContext.nodeField().size(); ++j)
  {
    IFieldElement field = wdContext.nodeField().getFieldElementAt(j);
  }

Armin

Former Member
0 Kudos

Hi Marshall Mathers,

Please find the below code. It will give you some idea.

I couldn't paste the exact code (syntax) since I don't know the singleton property of each node. If you want me to give the exact code please paste your singleton property value of each node.


int noOfRows = wdContext.nodeRecord().size();
for(int row=0;row<noOfRows;row++)
{
   wdContext.nodeRecord().getRecordElementAt(row).	
   get element of Record1 element.
    get Field node from Record 1 Node
     int fieldsSize = wdContext.nodeField().size();
       for(int fields =0; fields<fieldsSize; fields++)
       {
          String fieldName = wdContext.nodeField().getElementAtXXXXX(fields).getStringName();
String fieldValue = "";
if(size of node field1 > 0)
{
// According to the cardinality, Field1 node will contain either one element or Zero. So no need of any for loop here.
 fieldValue = get String value from field1;  
}
       }

}

Regards,

Jaya.

Edited by: VJR on Jul 2, 2009 11:02 AM

Edited by: VJR on Jul 2, 2009 11:03 AM

Former Member
0 Kudos

Hi Jaya,

I know your code makes logical sense but there are no such methods in the API as:



get element of Record1 element.

get Field node from Record 1 Node

if you think there is, please use actual code to show me and not pseudocode.

Kind regards,

Marshall.