Browse the versions of an item

Hi everyone ,

I'm currently trying to implement a C# method that should be able to browse all the versions of a

Part Item ,

thus we can read the states of the different versions and promote them .

but the problem is that I don't know how to get the versions of an Item .

Does anyone know how to solve this issue please ? 

Thanks in Advance 
Hamdi 

  • Hi Hamdi,

    in order to get all versions of an item you can query for items with a specific config_id (stable throughout all versions of an item) by specifying the condition "is not null" on the id property.
    In AML:

    <Item type="Part" action="get">
        <id condition="is not null" />
        <config_id>configIdOfTheItem</config_id>
    </Item>

    or using IOM (assuming we have an Innovator object called inn):

    var allVersions = inn.newItem("Part", "get");
    allVersions.setProperty("config_id", configIdOfItem);
    allVersions.setPropertyCondition("id", "is not null");
    allVersions = allVersions.apply();

    Hope this helps,

    C

  • 0 オフライン in reply to cogres

    Hi Cogres , 

    Thank you for your response , 

    it was really Helpful ,but just to know , I am using a C# method 

    I have an other question please ,

    In my code there is a case where I should promote the current Item 

    so here is the code I have used :

    //Obtain the Innovator instance from the Context Item
    Innovator inn = this.getInnovator();

    //Get the hexa id of the current EDM Part item
    string ID = this.getID();

    //Get the latest Part item with id "ID"
    Item latest = inn.getItemById("Part",ID);

    //Get the latest Part state
    string latestate = latest.getProperty("state");

    if(string.Equals(latestate, "serie", StringComparison.OrdinalIgnoreCase)){

    //get the list of generations of the current Part Item
    String config_id = latest.getProperty("config_id");
    Item allVersions = inn.newItem("Part", "get");
    allVersions.setAttribute("orderBy", "generation");
    allVersions.setProperty("config_id", config_id);
    allVersions.setPropertyAttribute("id", "condition", "is not null");
    allVersions = allVersions.apply();

    //get the Item count of the versions
    int vercount = allVersions.getItemCount();

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


    Item ItemI = allVersions.getItemByIndex(i);
    string state = ItemI.getProperty("state");


    //string generation = allVersions.getItemByIndex(i).getProperty("generation");
    if(string.Equals(state, "serie", StringComparison.OrdinalIgnoreCase))
    {
    string NextState = "Auslauf";
    ItemI.setAction("promoteItem");
    ItemI.setProperty("state", NextState);
    ItemI = ItemI.apply();
    }

    }

    }

    return latest.apply();

    the code written in Bold Format is what I have used to promote the Item 

    is these instructions are Correct ?  , or do you have a better method ?


    Thanks in Advance 
    Hamdi