Forum Discussion

Former_Member's avatar
Former_Member
Accelerator III
9 years ago

How To Get Single Part From Collection Of Items

I have a collection of items and  I want to retrieve single item from that -- If I write - return item_collection.getItemByIndex(0);                   It is giving whole list of Items rather than the one present at 0. Don't know why is it behaving like this.

6 Replies

  • Jasbir, Every Aras Item object includes the full collection + the item itself. So when you access item at specific Index you can:
    1. Access the item itself by using Aras methods (like getProperty() or setProperty()) for example this will return value of the property item_number:
      item_collection.getItemByIndex(0).getProperty("item_number")
    2. Access the XmlNode behind this Item for example this will return value of the property item_number using Xml:
      item_collection.getItemByIndex(0).node.SelectSingleNode("item_number").InnerText
    3. Access the XmlDocument of the Collection
      item_collection.getItemByIndex(0).dom
       
  • I think you could also do something like this Item returnItem =  item_collection.getItemByIndex(0); return returnItem
  • @dlindinger : Thanks for your input, I tried this but it is also giving me whole list of items rather than the one present at node 0. @Zahar : Thanks for your input, but is there any way I can return full Item rather than specific properties, as want all the properties inside it.    
  • I was able to reproduce the same behaviour. In order to get the single item returned I was successful with this line. return this.getInnovator().getItemById(item_collection.getItemByIndex(0).getType(), item_collection.getItemByIndex(0).getID());  
  • Jasbir, As I have mention in my previous answer using following syntax will return you specific Item in collection (or actually it's XmlNode representation): item_collection.getItemByIndex(0).node