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 

  • Hi Ocohen,

    could you explain your use case a little more, please? Do you want to convert an Item (collection) to an object of type List<Item>, where each member is an Item with item count 1 (although I'm not sure this would yield much of a benefit)? Or a single item to a List of some other type? Or am I misunderstanding your question?

    It would also help to know what you want to achieve by this conversion, i.e. what you want to make easier with it.

    Cheers,

    C

  • 0 オフライン in reply to cogres

    Hello,

    Thank you for the propt response.

    I am implementing a data verification and measurement subsystem.

    We implemented data delivery system from the PLM to out ERP. The data verification subsystem checks the Part BOM table agains the ERP BOM table to identify delivery issues.

    The measurement subsystem is a sort of BI, that collects data from the ARAS as well as from the ERP and other data bases, manipulates them and create data for statistical processes.

    The other applications does not use XML or similar protocols. As I had to  manipulate data from all of them, I select List<string[]> as the basis object structure; I convert data from all the DBs into this object type and manipulate it. Then I'm preparing the output data from thse objects.

    The following is an example of converting method, which is used widely; however, thre are instances that this method doesn't work, and I have specialized methods.

    The header input parameter is a list of the fields read from the PLM, serving as the columns names of the output table

    private List<string[]> itemToList(Item results, string[] header, out string err)
    {
    err = "";
    List<string[]> localClassList = new List<string[]>();
    // Convert the data received from the PLM into List <string[]>
    int resultsRowsCount = results.getItemCount();
    List<string> distinct = new List<string>();
    for (int rowPtr = 0; rowPtr < resultsRowsCount; rowPtr++)
    {
    Item itemTemp = results.getItemByIndex(rowPtr); // Exception will be caught in higher level
    if (itemTemp != null)
    {
    List<string> strArray = new List<string>();
    // Convert the data item by item according to the field names packed in HEADER.
    for (int i = 0; i < header.Length; i++)
    {
    string[] headerParts = header[i].Split('|');
    if (headerParts.Length == 1)
    strArray.Add(itemTemp.getProperty(header[i].Trim(), ""));
    else
    {
    Item it = itemTemp.getPropertyItem(headerParts[0]);
    if (it != null)
    strArray.Add(it.getProperty(headerParts[1].Trim(), ""));
    }
    }
    if (!distinct.Contains(strArray[0]))
    {
    distinct.Add(strArray[0]);
    localClassList.Add(strArray.ToArray());
    }
    }
    }
    return localClassList;
    }

  • 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