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

  • 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 
     

  • How I can pass multiple Config ID?

    I tried this way, But is not working for me, Can you please suggest here?

    let item = inn.newItem('Part', 'get');
    item.setProperty('classification', 'TYPE-A');
    item.setPropertyCondition("NAME", 'like');
    item.setProperty("NAME", `%Value_2%`);
    item = item.apply();
    let config_Id = []
    for (let i = 0; item.getItemCount() > i; i++) {
        var current_Item = item.getItemByIndex(i);
        config_Id.push(current_Item.getProperty("config_id"))
    }
    let all_version = inn.newItem('Part', 'get');
    all_version.setProperty('config_id', config_Id.join(","));
    all_version=all_version.apply();
    Thanks
    Vinoth S
  • Hi Vinoth,

    I think you’re pretty close. Try these two tweaks to the last few lines of your method:

    let all_version = inn.newItem('Part', 'get');

    all_version.setProperty('config_id', config_Id.join("|"));
    all_version.setPropertyCondition('config_id', 'like');
    all_version=all_version.apply();