How to convert an item to List ?

Hello,

I'm working with ARAS for few years now. I'm sending AML queries and receiving ITEMS back. Every case requires a new method of deciphering the data using getProperty or getPropertyItem calls. 

Is there any way to convert any item to array or list?

Regards

OCohen 

Parents
  • Hello,

    With the introduction of the RESTful API in 11.0 SP12, you can now get data from Innovator in a JSON format. This JSON can be easily serialized into an object in JavaScript by using the standard JSON.parse() function or in C# by using Newtonsoft's Json.NET library. I think this is the easiest way to handle the data since you can look up properties using code like item.id or item.item_number. However, this does require a bit of a learning curve and might require more significant changes than it's worth.

    As a simpler alternative, I think you'd be better suited using a data structure that has a Key-Value pair like a Dictionary as opposed to an array or a list. This will make it easier to both create and look up the data. You can see an example of how to build a Dictionary like this in the sample code below.

    // We'll assume a single item has been stored in a variable called myItem
    Dictionary<string, string> neutralDict = new Dictionary<string, string>();
    // Get the raw XML of the item object and loop through it to get the property names and values
    var nd = myItem.node;
    foreach (XmlNode child in nd.ChildNodes)
    {
        neutralDict.Add(child.LocalName, child.InnerText);
    }
    // We can now easily retrieve our data
    string itemConfigId = neutralDict["config_id"];
    string itemCreatedOn = neutralDict["created_on"];

    This sample code is just intended to show the general idea of mapping an Aras Item into a Dictionary, so it's not intended to handle cases like relationships or item properties. 

    Chris

  • Chris,

    Thank you very much.

    There are two problems with using Dictionary: (1) the returned data is not distinct; (2) the value of the dictionary is sensitive to the data structure. So I have to loop over the dictionary before I know the data structure, so we come back to instance-specific method.

    Regards

    O

Reply Children
No Data