web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

AX 2012 R2 - AOT - Query - Activation Date select

(0) ShareShare
ReportReport
Posted on by

I am creating a Query in the AOT that pulls up a few prices.  One of these is the Sales Price from the InventItemPrice table.   I know how to do most of it, except for pulling the correct one by its Activation Date.   For example.  For one of our Items, we have an activation date of 10/1/2013, 3/10/2014 and 5/28/2014.  Is there something obvious that I can do to only pull the correct one?  For this instance I would need to pick the 3/10/2014 record and use the Sales Price from that one.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Denis Macchinetti Profile Picture
    16,444 on at
    RE: AX 2012 R2 - AOT - Query - Activation Date select

    Hi

    Add a range on "ActivationDate" field like (lessThanUtcDate())

    Take care to enter your function within parentheses.

    Practically, you have to use the method on SysQueryRangeUtil class.

    More info at daxmusings.codecrib.com/.../custom-query-range-functions-using.html

  • Community Member Profile Picture
    on at
    RE: AX 2012 R2 - AOT - Query - Activation Date select

    Trying to understand the detail of the reply (thanks for the quick response).  

    1) Are you saying that in the AOT, when I add the InventItemPrice table as the Data Source, I then add a New Range, and for the field pick Activation Date, and for the Value enter (lessThanUtcDate()), and that is all I have to do?   Wouldn't that have me select the record for 10/1/2013 and the 3/10/2014?

    2) Is using Range and putting the Value in parenthesis - is that also how I can use Methods in a query?  Never learned that aspect of using AOT Queries.  If that is true - maybe could write a method that would select the one correct record.  Am I on the right track - or am I not understanding your post?  

    I am reading manuals and online blogs.  There is so much I see I have to learn - and the more I understand - the less I see I know...

  • Verified answer
    Denis Macchinetti Profile Picture
    16,444 on at
    RE: AX 2012 R2 - AOT - Query - Activation Date select

    Hi

    If you want a Range you can use the method dateRange at the same way.

    Have a look of the methods present on SysQueryRangeUtil class.

    However, if you want a "variable" range I think you have create a new method on SysQueryRangeUtil class and modify as your requirement.

    E.g. you can duplicate the DateRange method without any parameters and handle the date range according the SystemDate

  • Community Member Profile Picture
    on at
    RE: AX 2012 R2 - AOT - Query - Activation Date select

    Don't quite understand all you are saying, but I think I have enough to be able to dig into it.  Part of the process is just knowing what options I have - never knew I could use methods in the AOT query.

  • Denis Macchinetti Profile Picture
    16,444 on at
    RE: AX 2012 R2 - AOT - Query - Activation Date select

    Hi

    Feel free to write here for any issue.

  • Community Member Profile Picture
    on at
    RE: AX 2012 R2 - AOT - Query - Activation Date select

    Still trying to make sense of this.  Here is a method that is used in the InventItemPrice table.  It finds the current item/priceType  record from the table.

    public static InventItemPrice findCurrent(

        ItemId                              _itemId,

        CostingVersionPriceType  _priceType,

        InventDimId                     _inventDimId,

        TransDate                       _activationDate = systemDateGet(),

        InventSiteId                     _newSiteId      = '',

        InventItemCostingType   _costingType    = InventItemCostingType::Default,

        boolean             _forUpdate      = false

        )

    {

        InventItemPrice     inventItemPrice;

        InventTable         inventTable;

        InventDim           inventDim;

        InventDim           inventDimCriteria;

        InventDimParm       inventDimParm;

        ;

       

    if (_itemId)

        {

            inventTable                         = InventTable::find(_itemId);

            [inventDimParm, inventDimCriteria]  = InventItemPrice::setupInventDimParmAndCriteria(inventTable, _inventDimId);

            inventDimCriteria.InventSiteId      = InventItemPrice::changeSiteId(inventDimCriteria.InventSiteId, _newSiteId);

            inventItemPrice.selectForUpdate(_forUpdate);

       select firstonly inventItemPrice

           order by ActivationDate desc, CreatedDateTime desc   

        where inventItemPrice.ItemId                == _itemId

                   && inventItemPrice.PriceType             == _priceType

                   && inventItemPrice.ActivationDate        <= _activationDate

                   && (inventItemPrice.CostingType          == _costingType || _costingType == InventItemCostingType::Default)

                     #InventDimExistsJoin(inventItemPrice.inventDimId, inventDim, inventDimCriteria, inventDimParm);

        }

    return inventItemPrice;

    }

     

    Is there a way I can use this in my AOT Query?  Or am I going about this the wrong way?

     

    In my old system, I would add a 'method' called (IsCurrent) to the table that would pass back either a Y or N, so I could bypass all the N's.  Just don't know how to do the same thing with this setup.  Too bad we can't learn like they do in The Matrix - but that was just a movie - I know -- wishful thinking on my part!

  • Denis Macchinetti Profile Picture
    16,444 on at
    RE: AX 2012 R2 - AOT - Query - Activation Date select

    Hi

    More & less you can rebuild the above query using an AOT Query, but you can't call a single method with the above logic inside an AOT Query.

    You can only use the methods of the SysQueryRangeUtil class as range value.

    E.g. for manage the range on ActivationDate field.

  • Community Member Profile Picture
    on at
    RE: AX 2012 R2 - AOT - Query - Activation Date select

    I guess I need to figure out how to create a query that does what this method does.  Not sure how, but I will go back into research mode.  Thanks for the reply - I appreciate any pointing in the right direction you can throw my way.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans