Forum Discussion

hkhan's avatar
hkhan
Creator II
4 years ago
Solved

How can i get ID of previous generation

Hello im trying to get ID of gen 2 in a variable in Csharp can someone tell me how i can do that? ID              Gen 1                1 2                2 3                3 4          ...
  • Gopikrishnan's avatar
    4 years ago

    Hi HKhan

    I don't know the contextItem of your method call. Assuming your method call contextItem is part, you can run below code snippet

    Innovator innovator = this.getInnovator();
    string configId = this.getProperty("config_id");
    Item partItem = innovator.newItem("Part","get");
    partItem.setProperty("config_id", configId);
    partItem.setProperty("generation", "0");
    partItem.setAttribute("select", "id,generation");
    partItem.setAttribute("maxRecords", "2");
    partItem.setAttribute("orderBy", "generation DESC");
    partItem.setPropertyCondition("generation", "ge");
    partItem = partItem.apply();
    if(partItem.isError())
    {
    return innovator.newError("Error getting partItem " +partItem.getErrorString());
    }
    if(partItem.getItemCount() > 1)
    {
    return innovator.newResult("ID of Previous Generation is " +partItem.getItemByIndex(1).getID());
    }
    else
    {
    return innovator.newError("Previous Generation does not exist.");
    }