How can i get ID of previous generation
- 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.");
}