This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Problem getItemByIndex()

nx_plm - Wednesday, April 25, 2012 10:05 AM:

I have the following AML:

<Item
    <Relationships>
          <Item> </Item>
          <Item> </Item>
    </Relationships>
</Item>

 <Item> </Item>
 
 <Item> </Item>

When I lauch the query (Item results = InnovatorObj.apply())

I get 3 Items (int resultcounter = results.getItemCount();)

The problem starts when I just want to get the first Item.

  for (int i = 0; i < resultcounter; i++)
            {

                Item item = results.getItemByIndex(i); ------> the method does not get the first Item, it just get all of them and threat them as a single item
                item.isCollection(); -----> False
                int counter = item.getItemCount();

            }

 

Does anyone what I am doing wrong? I would like to get just the first Item:

<Item
    <Relationships>
          <Item> </Item>
          <Item> </Item>
    </Relationships>
</Item>

 

Thank you in advance

 

 



Eric Domke - Friday, April 27, 2012 8:16 AM:

If you look at the value of the variable item while debugging (say in Visual Studio), you will see the value of the entire result item.  This is an artifact of how the IOM manages memory.  In particular, each item generated by the IOM has multiple fields which include a dom field and a node field.  The getItemByIndex() method returns a new object of type Item which has the same DOM as the parent, but whose node property references the specific Item node within the DOM.  It is easy to get confused because the ToString() method returns the dom field while all the other methods operate on the node field.  Therefore, if you use the different IOM methods (e.g. getId() or getPropery()) on the variable item, you should get values for the current item only.

To say that again in a different way, your variable item should have the following fields:

dom = <Item>

    <Relationships>
          <Item> </Item>
          <Item> </Item>
    </Relationships>
</Item>

 <Item> </Item>
 
 <Item> </Item>

AND

node = <Item>

    <Relationships>
          <Item> </Item>
          <Item> </Item>
    </Relationships>
</Item>



Brian - Wednesday, May 2, 2012 7:40 AM:

Is there something specific that makes you think you are not getting the first item?

Your code looks ok to me.

Cheers,

Brian.



nx_plm - Wednesday, May 2, 2012 7:56 AM:

As Eric Domke said: I get some data which I expect when i am debugging in node field. But that node is handle as XML Data not as IOM . Then the data process is harder.

Thanks,

Daniel

 

 

 

 

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4