Custom AML - Select="max(generation)" - How to use SQL MAX in query?

Trying to write up a saved search to make viewing the generations of a part more convenient.  I am attempting to use the SQL standard MAX() in my "select" string, but am not having any luck. The AML is still returning the proper search, but the MAX is being discarded. What am I missing here?
  • Can add some bug reporting to this. First: When editing a "saved search", I return to my original grid that I was using it in and it is no longer available in the saved searches list. I have to log out and log in for the saved search to re-appear. Second: I am attempting to do some selection query work in my where clause. It seems that the the engine is refusing to evaluate my where clause statement. I have tried the following 'where="Model.generation>0"' this is being transformed to 'where="Model.generation>0" ' 'where="Model.ID in (SELECT Model.ID, MAX(Model.generation) GROUP BY Model.model_number, Model.MAJOR_REV, generation)" Both queries return with no errors as though the where clause wasn't used at all.
  • Hello, I can confirm that an AML query using the generation property in a where clause does not seem to return the expected results. That being said, it is possible to perform this same query using the following AML.
    
    
    <AML> <Item type="Part" action="get"> <generation condition="gt">0</generation> </Item></AML>
    
    
    Additionally, in recent versions of Innovator, SELECT statements are blocked from use in where clauses due to security concerns. Typically an error is thrown indicating this. Could you please provide the full AML query that you are using? That being said, the most recent generation of an Item is always flagged with the "is_current" boolean, so you can perform the same query for an item with the highest generation by using the AML below.
    
    
    <AML><AML> <Item type="Part" action="get"> <is_current>1</is_current> </Item></AML>
    
    
    I also want to note that, by default, only the most recent generation of an Item is returned in an AML search unless you are specifically querying on the generation property. Chris _________________________ Christopher Gillis Aras Labs Software Engineer
  • Chris, In this particular scenario, I am trying to return every revision of the current part at its highest relevant current generation. e.g. Rev 1 gen 1 Rev 1 gen 2 Rev 2 gen 1 Rev 2 gen 2 Rev 2 gen 3 returning Rev 1 Gen 2 Rev 2 Gen 3 This default behavior of returning only the most recent active result is proving to be hard to work around. At this point, I'm not sure what else to do aside from writing a server side method that query with raw SQL. In the meantime, I now have a bug in that a object is refusing to increment its major rev.
  • Hello, By default, the generation property does not reset whenever an Item's major_rev is increased. Instead, we can take advantage of the fact that the major_rev property is increased whenever an item is edited from a Released state. Because of this, we can run the AML query below to look for only the latest generation of each Major Revision of an item.
    <AML>
    <Item type="Part" action="get">
    <state>Released</state>
    <generation condition="gt">0</generation>
    </Item>
    </AML>
    Note, that we query using the generation tag in the AML in order to return all instances of a Part, not just the most current version. As a general practice, we recommend against using direct SQL in a Method as it bypasses the Aras permission model. Lastly, could you please provide the scenario where your item is not incrementing the major_rev? Chris ____________________________________ Christopher Gillis Aras Labs Software Engineer