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               4

  • 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.");
    }

3 Replies

  • 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.");
    }

    • hkhan's avatar
      hkhan
      Creator II

      can you also tell what partItem.setPropertyCondition("generation", "ge"); does? like what does "ge" mean?

      • Gopikrishnan's avatar
        Gopikrishnan
        Accelerator II

        ge stand for greater than or equal to. Some other condition are: 

        eq equal
        ne not equal
        le less than or equal to
        gt greater than
        lt less than
        like
        not like
        between
        not between
        in
        is null
        is not null

        Thank You

        Gopikrishnan R