Pages

Wednesday, August 16, 2017

How to find previously used addresses or other older records in Valid Time State Tables for Date Effective Data in Microsoft Dynamics 365 or AX

In Dynamics (AX/365) there is a concept of "Valid Time State Tables" that contain date effective data.  In this post, you'll find code to list all the previous addresses tied to an individual record.

If you are not familiar with this type of data, the simplest example to wrap your head around is postal addresses. If you are, just skip the next paragraph.

Let's say you send an order/invoice to a customer at 123 South St on 1/1/2017. Then a few months later, the customer moves locations to 456 North Ave and you update their address in Dynamics. All is good so far. Then for some reason you need to reprint the 1/1/2017 invoice...well that address record for 123 South St still exists in the database, but it's "ValidTo" is in the past. This way you have the historical addresses.

This sample job below takes an address and loops through the older versions of that address. This method can be used to seek any data in valid time state tables though.

static void AlexOnDAXFindOldAddresses(Args _args)
{
    CustTable                       custTable = CustTable::find("ZZZZ");
    LogisticsPostalAddress          logisticsPostalAddress;
    LogisticsPostalAddress          logisticsPostalAddressOld;
    utcDateTime                     utcMinVal = DateTimeUtil::minValue();
    utcDateTime                     utcMaxVal = DateTimeUtil::maxValue();
    
    // Active address
    logisticsPostalAddress = CustTable.postalAddress();
    info("Current: " + logisticsPostalAddress.Address);
    
    setPrefix("Previous Addresses");
    
    // This will loop through the inactive addresses in order
    while select validTimeState(utcMinVal, utcMaxVal) logisticsPostalAddressOld
        order by ValidTo desc
        where logisticsPostalAddressOld.Location        == logisticsPostalAddress.Location      &&
              logisticsPostalAddressOld.RecId           != logisticsPostalAddress.RecId
    {
        info(strFmt("%1 [%2-%3]",
                    logisticsPostalAddressOld.Address,
                    logisticsPostalAddressOld.ValidFrom,
                    logisticsPostalAddressOld.ValidTo));
    }
}



6 comments:

  1. i am a dummy when it comes to these kind of studies or tasks. i am glad i got to this post and had it made way too easy for me. thank you so much for posting. keep us updated

    ReplyDelete
  2. First time user , service fantastic , was delivered 2 hrs after order placed . Will be using again Europa-Road Kft

    ReplyDelete
  3. Indian 3d Product Design Company & 3d Product Design Services
    Quickgunz Pvt Ltd offer many 3D Product Design Services or artist impressions for the architectural, advertising, engineering, medical industry and people who insists to require our quality 3d product Design’ help and services to place their competitors behind.you can view our services, samples of 3d animation, modeling, illustrations and merchandise visualizations.To know more about our 3D product Design company Visit our website.
    3d Product Design
    3d Product Design Company

    ReplyDelete

  4. We are Offering For Vip Clients With Five Star Hotel Hi Profile Model Call center escorts in Delhi Airhostess, Celebrity Independent Escorts Available in Delhi. If You are Success Your Dream Enjoy With Hi Profile Delhi escorts and Like Actress Great Feeling and Awesome Satisfaction Contact hot escorts in Delhi We Have Original and Decent Escort Service in Shangrila Hotel Delhi. Very Attractive, Frank and Friendly Behavior Best Call Girl Services in Delhi. Looking for some fun in between the monotonous schedule of work? Welcome to Top 7 Escorts in Aerocity for the fun that you always wanted in between your hectic schedule. The young and charming teen escorts in Aerocity are just a call or an e-mail away at your service. Also there are a very few of escort agencies who are providing ebony escorts in Delhi or in other words Black escort girls in delhi. In foreigner escorts Black girls are most demanded now a days

    ReplyDelete
  5. I imagine that you should now like a casino that can satisfy you with its extremely extraordinary achievement. I feel that you would be exceptionally intrigued, at that point you should begin to play in a casino that can help and enjoyment you with extraordinary delight. No one but you can casumo casino review significantly take bring in cash on playing at the casino

    ReplyDelete

  6. Emblix Academy – Digital marketing institute in KPHB, we address all major and minor aspects required for any student’s advancement in digital marketing. Clutch USA named our Digital Marketing Institute the best SEO firm. for more info visit here :- https://emblixacademy.com/

    ReplyDelete