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]",


  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

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

  3. 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

  4. By clicking on the link, you can see a variety of postcards for your beloved stepmother. Thus, you can order flower delivery on the same site along with postcards. If anything, you can also buy gift boxes or pour it yourself, which is very, very convenient. In general, please your loved ones and never quarrel!

  5. Fantastic news everyone, I think for people who can now get a tattoo for themselves, you can use a splendid site bat tattoo design ideas there you can quickly pick a specialist for yourself who will play out everything and photo work for which there is a phenomenal opportunity to pick an organized able.

  6. Kasyno online to normalna strona do grania, sam czasami gram tam na automatach, jeśli uda mi się wygrać, pieniądze są najczęściej wypłacane tego samego dnia, więc kasyno online wszystko jest bez oszustwa, osobiście przeze mnie zweryfikowane. Możesz więc sam spróbować tam zagrać.

  7. Everything considered I saw one charming article about how Connect Amazon S3 to WooCommerce . I figure the information will be appropriate for individuals who somehow need to start working with Amazon. For example, this will be essential for vendors on the Amazon site, since you can learn new commonly secret methodologies that can make your life and usage of the stage more straightforward.

  8. Nice to see you! You can hire a subject professional for any type of work. Our esssy writer specialize across all subjects and academic levels. Their profound expertise is the key to brilliant results and fast delivery. Any task is do-able with their pro help. That is why we do our best to improve the services we provide and make sure we are able to meet our customers’ demands every single time they place an order.