# Iterating a container using BusinessConnector

**URL:** <https://www.dynamicsuser.net/t/iterating-a-container-using-businessconnector/55734>\
**Category:** Developer Forum\
**Created:** [November 10, 2014, 8:12pm UTC](https://www.dynamicsuser.net/t/iterating-a-container-using-businessconnector/55734 "2014-11-10T20:12:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rigamonk](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@rigamonk](https://www.dynamicsuser.net/u/rigamonk)\
**Post date:** [November 10, 2014, 8:12pm UTC](https://www.dynamicsuser.net/t/iterating-a-container-using-businessconnector/55734/1 "2014-11-10T20:12:11Z")

</div>

I am call a function from C# using the business connector dll. I have no idea how to do this. I tried instantiating a container, but there is no constructor.

So, briefly, I am calling a function that returns an object (CallStaticClassMethod) and this object is a container. How do I convert and get the values within that container.

Any help appreciated.

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [November 10, 2014, 9:13pm UTC](https://www.dynamicsuser.net/t/iterating-a-container-using-businessconnector/55734/2 "2014-11-10T21:13:13Z")

</div>

If you have no idea how to do something, your first reaction should be to find and read [the documentation](http://msdn.microsoft.com/en-us/library/aa659581.aspx). Nevertheless you should avoid using Business Connector, especially in AX 2012 which offers many better options. If you tell us what you’re trying to do, we might be able to show you how to do it without Business Connector.

If you decide to use Business Connector despite everything, realize that you don’t don’t need to instantiate the container if you already get it from the method. If you check the type of the object you receive, you’ll find that it’s [AxaptaContainer](http://msdn.microsoft.com/en-us/library/microsoft.dynamics.businessconnectornet.axaptacontainer.aspx). Use its method and properties to manipulate the container.

---

<div class="post-metadata">

**Author:** ![rigamonk](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@rigamonk](https://www.dynamicsuser.net/u/rigamonk)\
**Post date:** [November 10, 2014, 9:19pm UTC](https://www.dynamicsuser.net/t/iterating-a-container-using-businessconnector/55734/3 "2014-11-10T21:19:41Z")

</div>

There is nothing in the Object explorer for the business connector. Nor is there any handy C#-\>AX programming documentation.

I am using AX 4 and calling a class function. I am unaware of another way to do this from within .Net than through the business connector.

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [November 10, 2014, 9:50pm UTC](https://www.dynamicsuser.net/t/iterating-a-container-using-businessconnector/55734/4 "2014-11-10T21:50:54Z")

</div>

I added the tag with your version of AX to your question (among other tags). Please do it by yourself next time.

The documentation for AX 4.0 is [here](http://msdn.microsoft.com/en-us/library/aa659581%28v=ax.10%29.aspx) - you can find it at any time by using your favorite search engine. Your other option would be using [AIF](http://msdn.microsoft.com/en-us/library/aa570085%28v=ax.10%29.aspx), nevertheless I can’t say from the (lack of) description whether it would be a wise choice or not. Unfortunately you’ll miss best features for integration (e.g. custom services and proxy classes) until you upgrade to AX 2012.

---

<div class="post-metadata">

**Author:** ![rigamonk](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@rigamonk](https://www.dynamicsuser.net/u/rigamonk)\
**Post date:** [November 19, 2014, 4:44pm UTC](https://www.dynamicsuser.net/t/iterating-a-container-using-businessconnector/55734/5 "2014-11-19T16:44:48Z")

</div>

I found some code to iterate a container, however, it seems i can;t get what is wrapped within the conainer

AxaptaContainer path = (AxaptaContainer)ax.CallStaticClassMethod(“DocumentHandling”, “ItemData”, “1000000”);

for (int i = 1; i \< path.Count - 1; i++)

{

string somestring = path.get\_Item(i).ToString();

}

Gives me “Microsoft.Dynamics.BusinessConnectorNet.AxaptaContainer”. This function is supposed to be returning strings containing paths to document handling objects

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [November 19, 2014, 4:57pm UTC](https://www.dynamicsuser.net/t/iterating-a-container-using-businessconnector/55734/6 "2014-11-19T16:57:59Z")

</div>

No, you’re wrong. The return type _get\_Item()_ is _Object_, not _string_, because you can use any value types in containers. You can see the type in [the documentation](http://msdn.microsoft.com/en-us/library/microsoft.dynamics.businessconnectornet.axaptacontainer.get_item.aspx).

If the type of your item(s) is _AxaptaContainer_, you have a nested container there. Unfortunately your code doesn’t support that - you should rewrite it to iterate through nested containers too, possibly by using a recursive method.
