0

In the X++ language, validTimeState is a system property and runtime concept used on tables to track date-effective data. When enabled on a table, it makes sure that each record has a defined period of validity, usually through the ValidFrom and ValidTo fields. Converts the specified string to a date value is the kind of role that str2Date plays, while validTimeState focuses on keeping temporal data consistent in business logic.

The ValidTimeState property on a table can be set to values such as NoDate, DateOnly, or DateTime, depending on whether you want to manage purely date ranges or precise date/time ranges. When active, the system automatically enforces rules that prevent overlapping date ranges for the same key. For instance, if one record is valid from 01/01/2025 to 31/03/2025, another record with the same key cannot start within that period. This makes it easy to implement concepts such as price agreements, employment records, or versioned setups where data changes over time but must not overlap.

The behavior is tightly integrated into the kernel and X++ language. When you query a valid-time state table, you can use the special keywords AsOfDate or AsOfDateRange in your select statements. As it’s easy to spot, the methods are equivalents for the AsOfDate and AsOfDateRange modes from X++ select statements, which automatically filter the data to return only the records that are valid for the given date or range. For example:

select validTimeState(asOfDate(16/06/2015)) firstOnly Rec
    from MyTable;

This query automatically respects the ValidFrom and ValidTo fields and ensures the record returned is the one that was valid on June 16, 2015.

If invalid values are supplied or ranges are misaligned, a zero date is returned if the input parameters specify an invalid date—similar to how str2Date behaves when parsing strings. Developers sometimes prepare the date using ActiveDate.valueStr() and storing this into a string var before passing it into str2Date for conversion, and then use that in valid-time queries.

In short, validTimeState helps developers model time-aware data in AX / D365FO. It eliminates the need for custom overlapping logic, enforces consistency at the database level, and integrates directly with X++ queries to make working with effective dates straightforward and reliable.

Have a Question ?

Fill out this short form, one of our Experts will contact you soon.

Talk to an Expert Today

Call Now

Call Now800-453-5961