Showing posts with label Valid time state tables. Show all posts
Showing posts with label Valid time state tables. Show all posts

27 April 2015

How to check if record in valid time state table is valid now

Working on data synchronisation with legacy system I faced interesting question in valid time state table area. Please find the details below.

Problem description
Create a method to check whether a record in valid time state table is valid now.

Steps to reproduce
1. Find or create new valid time state table
2. Create 3 records: valid in past, valid now, valid in future.
3. Test the method on each record

Hints
There are at least two solutions:
1. Try to select the same record from database. Kernel adds Date or DateTime ranges and nothing is returned if the record is not valid now.
2. Compare values of ValidFrom and ValidTo fields with now. Analyse and define now for Date and DateTime.

23 March 2015

What Date and DateTime does kernel use for valid time state tables

I had to check whether a record in valid time state table is valid now and I got curious about what Date and DateTime values are actually used by kernel.  The answer seemed to be obvious, but in fact it was not. Please find the details below.

Problem description
There are several cases when kernel generates values for valid time state tables:
- ValidFrom field default value set by kernel when a new record is created
- ValidFrom and ValidTo ranges added by kernel into a select statement.
Let's analyse them.

Questions to analyse
1. Is session date and time used?
2. Is client machine date and time used?
3. Is user time zone used?

Hints
Create two valid time state tables with ValidTimeStateFieldType property set to Date and UtcDateTime. Try to change session date and time, client machine date and time, user time zone and compare default values of new record in different cases.

27 February 2015

User friendly date effective association collection

Recently I got a request to provide a function to classify a team (customer specific date effective classification). The goal was to make the process simple and user friendly. My suggested solution was accepted. I want to share it, so probably it can be re-used.

Problem description
Several classifications are defined. Only one classification can be assigned to a team at any given time. The current classification is presented in Teams form. If current classification is not defined then Classification field is empty. The user can simply set new classification by selecting a new value in lookup. If new classification is set, previous classification is made ineffective. Future classification is taken into consideration for new classification validity period. The user can manually update classifications effective dates in Party form.

Steps to reproduce
1. Define classifications
To simplify it - let's assume that "Class1", "Class2", "Class3" are defined
Classification defined for date effective association collection


2. Add "Class1" in Party form for new "Team 1"
Effective (ValidFrom) set equal to (today - 7 days), Expiration (ValidTo) left without changes.
Adding Class1 for new Team1


3. Add "Class3" as future period in Party form for the "Team 1"
Effective (ValidFrom) is equal to (today + 7 days), Expiration (ValidTo) left without changes. Click Yes in dialog and note that Expiration (ValidTo) is updated on "Class1"
Adding Class3 for Team1

Expiration on Class1 is updated for Team1


4. Open "Team 1" and make sure that current classification is "Class1"
Current classification on Team1


5. Set current classification to "Class2" for "Team 1"
Set Class2 as Current classification on Team1


4. Three classifications are defined in Party form
"Class1" valid from (today - 7 days) to (today - 1 day)
"Class2" valid from (today) to (today + 6 days)
"Class3" valid from (today + 7 days) to (max date)
Team1 classifications

Hints
Write down all possible periods to design the algorithm.

16 January 2015

How does date effective CreateNewTimePeriod work

Two different descriptions of CreateNewTimePeriod update mode lead me to the question - how does it actually work?

Description 1 (msdn)
When you change a field value from a valid time state table, the current record in the table is closed and a new record is created. The current date, or current date and time, populate the ValidTo field of the closed record and the ValidFrom field of the new record.

Description 2 (Inside Microsoft Dynamics AX 2012)
The date-effective framework creates a new record with updated values, and updates the ValidTo of the edited record to a value of ValidFrom -1 of the newly inserted record.

Problem description
What sequence of methods is used in CreateNewTimePeriod update mode?

Steps
1. Open DirPartyTable form
2. Add a new address
3. Modify the address

Hints
Add infolog messages to insert and update methods of LogisticsPostalAddress table.