Date effectiveness in Dynamics 365 allows developers to easily create date range fields. Date ranges are used to define record validity between the specified dates, for example, defining employee contract dates and defining vendor license validity.
This feature in D365 significantly reduces the amount of time that developers spend on developing business logic/code and also provides a consistent approach to implement data range fields.
This recipe will demonstrate the basics of date effectiveness. We will create a new table to implement date range validation.
Run Visual Studio as admin:
- Load your earlier project.
- Add a new TablePktEmployeeContract
Set the property as follows:
Note the two new fields that are automatically added to the table, as shown in the following screenshot (Valid To and Valid From):
3. Now create a new index as follows and add fields as follows:
4. Set the following mentioned property for the index here:
5. Now open the table and enter some records in this table itself instead of creating a new form for the table. Right-click on Table and select Browse table:
How it works…
- set the ValidTimeStateFieldType property to Date in the SysEmailTable table. This automatically creates two new fields–ValidForm and ValidTo that are used to define a date range.
- add the created fields to the primary index where the Emp1Num field is used and adjust the index’s properties
- set the AlternateKey property to Yes in order to ensure that this index is a part of an alternate key.
- set the ValidTimeStateKey property to Yes in order to specify that the index is used to determine valid date ranges.
- set the ValidTimeStateMode property to NoGap in order to ensure that email templates with the same identification number can be created within continuous periods. This property can also be set to Gap, allowing non contiguous date ranges.