<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.aras.com/community/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Custom AML - Select=&amp;quot;max(generation)&amp;quot; - How to use SQL MAX in query?</title><link>https://www.aras.com/community/f/development/3426/custom-aml---select-max-generation---how-to-use-sql-max-in-query</link><description>Trying to write up a saved search to make viewing the generations of a part more convenient.&amp;#160; I am attempting to use the SQL standard MAX() in my &amp;quot;select&amp;quot; string, but am not having any luck. The AML is still returning the proper search, but the MAX is</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Custom AML - Select="max(generation)" - How to use SQL MAX in query?</title><link>https://www.aras.com/community/thread/916?ContentTypeID=1</link><pubDate>Fri, 13 Oct 2017 09:16:24 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:889c623e-0102-455b-9089-44ed91083426</guid><dc:creator>Christopher Gillis</dc:creator><description>Hello,

By default, the generation property does not reset whenever an Item&amp;#39;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.

&lt;pre&gt;&lt;code&gt;&amp;lt;AML&amp;gt;
&amp;lt;Item type=&amp;quot;Part&amp;quot; action=&amp;quot;get&amp;quot;&amp;gt;
&amp;lt;state&amp;gt;Released&amp;lt;/state&amp;gt;
&amp;lt;generation condition=&amp;quot;gt&amp;quot;&amp;gt;0&amp;lt;/generation&amp;gt;
&amp;lt;/Item&amp;gt;
&amp;lt;/AML&amp;gt;&lt;/code&gt;&lt;/pre&gt;


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&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom AML - Select="max(generation)" - How to use SQL MAX in query?</title><link>https://www.aras.com/community/thread/915?ContentTypeID=1</link><pubDate>Thu, 12 Oct 2017 18:28:33 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:2c458262-719e-4793-9aef-31742098f6a9</guid><dc:creator>Former Member</dc:creator><description>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&amp;#39;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.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom AML - Select="max(generation)" - How to use SQL MAX in query?</title><link>https://www.aras.com/community/thread/905?ContentTypeID=1</link><pubDate>Tue, 10 Oct 2017 16:48:56 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:2f53869b-e720-476e-ae88-394465d38abc</guid><dc:creator>Christopher Gillis</dc:creator><description>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.

&lt;pre&gt;&lt;code&gt;

&amp;lt;AML&amp;gt; &amp;lt;Item type=&amp;quot;Part&amp;quot; action=&amp;quot;get&amp;quot;&amp;gt; &amp;lt;generation condition=&amp;quot;gt&amp;quot;&amp;gt;0&amp;lt;/generation&amp;gt; &amp;lt;/Item&amp;gt;&amp;lt;/AML&amp;gt;

&lt;/code&gt;&lt;/pre&gt;


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 &amp;quot;is_current&amp;quot; boolean, so you can perform the same query for an item with the highest generation by using the AML below.

&lt;pre&gt;&lt;code&gt;

&amp;lt;AML&amp;gt;&amp;lt;AML&amp;gt; &amp;lt;Item type=&amp;quot;Part&amp;quot; action=&amp;quot;get&amp;quot;&amp;gt; &amp;lt;is_current&amp;gt;1&amp;lt;/is_current&amp;gt; &amp;lt;/Item&amp;gt;&amp;lt;/AML&amp;gt;

&lt;/code&gt;&lt;/pre&gt;


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&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Custom AML - Select="max(generation)" - How to use SQL MAX in query?</title><link>https://www.aras.com/community/thread/898?ContentTypeID=1</link><pubDate>Mon, 09 Oct 2017 14:45:44 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:f86e6ebe-2d75-4850-842a-95ecda9c0e2e</guid><dc:creator>Former Member</dc:creator><description>Can add some bug reporting to this.

First: When editing a &amp;quot;saved search&amp;quot;, 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

&amp;#39;where=&amp;quot;Model.generation&amp;gt;0&amp;quot;&amp;#39; this is being transformed to &amp;#39;where=&amp;quot;Model.generation&amp;amp;gt;0&amp;quot; &amp;#39;

&amp;#39;where=&amp;quot;Model.ID in (SELECT Model.ID, MAX(Model.generation) GROUP BY Model.model_number, Model.MAJOR_REV, generation)&amp;quot;

Both queries return with no errors as though the where clause wasn&amp;#39;t used at all.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>