tbischel - Monday, March 15, 2010 3:56 PM:
In innovator, there is an option to look at an item's past revisions. What I would like to do is retrieve a list of items via the IOM.
The obvious thing is to search on a property, and specify the generation number... but that doesn't work when I don't have an indexed property that would stay consistent across generations.
Looking at the itemtype definition, there is the config_id, which points to an item of the same type (I originally thought this might be a pointer to the last version of this item, but this seems to not be the case.)
There is also a revision item, but it comes up as null when I try to fetch it... plus the item definition for revision doesn't seem to contain a pointer to another item.
So what do I do?
RobMcAveney - Tuesday, March 16, 2010 12:22 PM:
You're on the right track with config_id. This property contains the id of the first generation in the chain and is consistent across all generations of the same item. The answer to your question really depends on what you want:
- A previous generation of a known item
- A previous generation of an item to be found based on the current generation's property values
- A previous generation of an item to be found based on the previous generation's property values
- The generation of an item that was Released (or Effective or Latest) as of a date
FYI, if you ever want to know how the client is doing something (like finding all previous generations) you should turn on the "Save Requests" option in Tools->Admin. This will save all the AML that is getting submitted to the server in your working directory.
Rob
tbischel - Tuesday, March 16, 2010 5:54 PM:
Rob,
Thanks for the tip, the "save requests" feature is quite useful. In my case, I have the top level item id already, I am trying to get a list of items ordered by generation. Based on the AML, it looks like I should do something like this:
Item latest; //Set somewhere else
String config_id = latest.getProperty("config_id");
Item past = InnovatorServer.newItem("foo", "get");
past.setAttribute("orderBy", "generation");
past.setProperty("config_id", config_id);
past.setPropertyAttribute("id", "condition", "is not null");
past = past.apply();
for(int i=0; i<past.getItemCount(); i++)
{
System.Console.WriteLine("generation: " + past.getItemByIndex(i).getProperty("generation"));
}
This works fine... I don't quite understand why the "is not null" condition matters, as every item should have an id. When I don't have that line in though, it does fail.
RobMcAveney - Tuesday, March 16, 2010 6:32 PM:
The server keys off of a few properties to decide whether to return only the latest generation or all. The id property is one of them, so putting in any criteria on id will alter the query. I usually use something like <generation condition="gt">0</generation> because it makes a little more sense. There may be more straightforward ways (I seem to remember a flag on Item at some point), but I know this way works.
Rob
Xavier Bertschy - Thursday, October 30, 2014 6:36 AM:
Hello,
I would like to do almost the same thing, expect I only want to get the first Major Rev of each Part (i.e. Part A (whatever the generation is), Part B (whatever the generation is), etc.). I used:
past.setAttribute("orderBy", "is_released");
or
past.setPropertyCondition("state", "Released")
but it doesn't change anything. Does anyone know how can I achieve this?
Thanks!
Xavier
DavidSpackman - Friday, October 31, 2014 12:16 AM:
Hi Xavier,
I think this will be more complicated than a simple query.
If you follow the full lifecycle of part only one generation (at a time) of the part can be (one generation may be both)
- is_released = 1,
- is_current = 1
See an example of a document item in our system.
Generation 12,14 have been in a "released" state in the past, but once superseded this field it no longer set, and there is no flag in the system to let me know it was released. I only know because of my understanding of the lifecycle map.
The best way to visualise this yourself is to take a single part through a Change Management workflow a couple of times to release and revise.
You can use the revision dialog or SQL to see what information changes.
Example SQL for a document
SELECT
ITEM_NUMBER,
ID,
CONFIG_ID,
MAJOR_REV,
GENERATION,
STATE,
IS_CURRENT,
IS_RELEASED,
*
FROM
innovator.DOCUMENT D
WHERE
D.ITEM_NUMBER = 'D-000004'
ORDER BY
D.GENERATION
Sorry not a solution, but something to consider.
DavidSpackman - Friday, October 31, 2014 12:23 AM:
Here is an example in SQL based on this http://stackoverflow.com/questions/6841605/get-top-1-row-of-each-group
------------------------------------------
--Raw Data
SELECT
ITEM_NUMBER,
ID,
CONFIG_ID,
MAJOR_REV,
GENERATION,
STATE,
IS_CURRENT,
IS_RELEASED,
*
FROM
innovator.DOCUMENT D
WHERE
D.ITEM_NUMBER = 'D-000004'
ORDER BY
D.GENERATION
------------------------------------------
------------------------------------------
-- Lowest Major Rev / Generation
;WITH cte AS
(
SELECT *,
ROW_NUMBER() OVER (PARTITION BY MAJOR_REV ORDER BY GENERATION) AS rn
FROM
innovator.DOCUMENT D
WHERE
D.ITEM_NUMBER = 'D-000004'
)
SELECT
ITEM_NUMBER,
ID,
CONFIG_ID,
MAJOR_REV,
GENERATION,
STATE,
IS_CURRENT,
IS_RELEASED,
rn,
*
FROM
cte
WHERE
rn = 1
------------------------------------------
Xavier Bertschy - Monday, November 3, 2014 4:49 AM:
Thanks David! It will helps me to improve my understanding.
For my problem, I could use a : past.setProperty("state","Released"); it helps to retrieve only the Released part.
DavidSpackman - Wednesday, November 5, 2014 1:01 AM:
Hi Xavier,
For my problem, I could use a : past.setProperty("state","Released"); it helps to retrieve only the Released part.
How many items does that query return?
Not relevant, but your query past.setPropertyCondition("state", "Released") would have generated the following (invalid) AML
<state condition="Released"></state>
Refer to 2.4.2 Property Attributes in the Programmers Guide to see available conditions attributes.
Example
Item qryItem = this.newItem("Part","get");
qryItem.setAttribute("select","item_number,description,cost");
qryItem.setProperty("cost", "100");
qryItem.setPropertyCondition("cost", "gt");
Item results = qryItem.apply();
Is the same as
<AML>
<Item type="Part" action="get" select="item_number,description,cost">
<cost condition="gt">100</cost>
</Item>
</AML>
Xavier Bertschy - Wednesday, November 5, 2014 6:11 AM:
Hi David,
For my problem, I could use a : past.setProperty("state","Released"); it helps to retrieve only the Released part.
How many items does that query return?
-> it actually returns every items which has the property "config_id" set to the config_id of my choice and are in "Released" state.
Not relevant, but your query past.setPropertyCondition("state", "Released") would have generated the following (invalid) AML
<state condition="Released"></state>
-> yes right, I've just got it right after posted on the forum!
But what is the difference between setPropertyAttribute() and setPropertyCondition() ?
Thanks again David,
Xavier
DavidSpackman - Wednesday, November 5, 2014 7:40 PM:
setPropertyCondition is just a shortcut to access the condition attribute for a property
setPropertyCondition()
Set the condition attribute on a property
public void setPropertyCondition( string propertyName, string condition )
setPropertyAttribute()
Set any attribute for a property
public void setPropertyAttribute( string propertyName, string attributeName, string attributeValue )
Examples (See Programmer's Guide)
These will achieve the same result.
myItem.setPropertyCondition("modified_on", "gt");
myItem.setPropertyAttribute("modified_on","condition","gt");
