Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microsoft Dynamics AX 2012 Development Cookbook

You're reading from   Microsoft Dynamics AX 2012 Development Cookbook Customizing Dynamics AX to suit the specific needs of an organization is plain sailing when you use this cookbook of modifications. With more than 80 practical recipes it's the perfect handbook for all Dynamics AX developers.

Arrow left icon
Product type Paperback
Published in May 2012
Publisher Packt
ISBN-13 9781849684644
Length 372 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Mindaugas Pocius Mindaugas Pocius
Author Profile Icon Mindaugas Pocius
Mindaugas Pocius
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Microsoft Dynamics AX 2012 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
1. Preface
1. Processing Data FREE CHAPTER 2. Working with Forms 3. Working with Data in Forms 4. Building Lookups 5. Processing Business Tasks 6. Integration with Microsoft Office 7. Using Services 8. Improving Development Efficiency 9. Improving Dynamics AX Performance

Using the date effectiveness feature


Date effectiveness is a new feature in Dynamics AX 2012 allowing developers to easily create date range fields. Date ranges are used for defining record validity between the specified dates, for example, defining employee contract dates.

This feature significantly reduces the amount of time that developers spend writing code and also provides a consistent approach to implement data range fields.

This recipe will demonstrate the basics of date effectiveness. We will implement date range validation on the standard E-mail templates form.

How to do it...

Carry out the following steps in order to complete this recipe:

  1. 1. In the AOT, find the SysEmailTable table and change its property as shown in the following table:

    Property

    Value

    ValidTimeStateFieldType

    Date

  2. 2. Notice the two new fields that are automatically added to the table:

  3. 3. Add the newly created ValidFrom and ValidTo fields to the existing emailIdIdx index and change the properties shown in the following table:

    Property

    Value

    AlternateKey

    Yes

    ValidTimeStateKey

    Yes

    ValidTimeStateMode

    NoGap

  4. 4. The index should look similar to the following screenshot:

  5. 5. Next, add the ValidFrom and ValidTo fields to the table's Identification group:

  6. 6. In the AOT, find the SysEmailTable form, refresh it using the Restore command which can be found in the form's right-click context menu. Then, locate its data source named SysEmailTable and change its properties as follows:

    Property

    Value

    ValidTimeStateAutoQuery

    DateRange

    ValidTimeStateUpdate

    Correction

  7. 7. In order to test the results, navigate to Organization administration | Setup | E-mail templates and notice the newly created fields: Effective and Expiration columns. Try creating records with the same E-mail ID and overlapping date ranges—you will notice how the system is proposing to maintain valid date ranges:

How it works...

We start the recipe by setting the ValidTimeStateFieldType property to Date on the SysEmailTable table. This automatically creates two new fields: ValidFrom and ValidTo that are used to define a date range.

Next, we add the created fields to the primary index where the EmailId field is used and adjust the following index's properties:

  • We set the AlternateKey property to Yes to ensure that this index is a part of an alternate key.

  • We set the ValidTimeStateKey property to Yes to specify that the index is used to determine the valid date ranges.

  • We also set the ValidTimeStateMode property to NoGap to ensure that e-mail templates with the same identification number can be created within continuous periods. The property can also be set to Gap allowing non-continuous date ranges.

Finally, we adjust the SysEmailTable form to reflect the changes. We add the newly created ValidFrom and ValidTo fields to the SysEmailTable table's Identification group so that they automatically appear on the form's Overview grid. We also change a few properties of the SysEmailTable data source:

Set the ValidTimeStateAutoQuery property to DateRange to ensure that all records are visible. The default AsOfDate value could be used if we want to display only the records for the current period.

Set the ValidTimeStateUpdate property to Correction, allowing the user to modify the dates.

There's more...

Forms with date effective records can be enhanced with an automatically-generated toolbar for filtering the records. This can be done with the help of the DateEffectivenessPaneController application class.

In order to demonstrate that, let's modify the previously used SysEmailTable form and add the following code to the bottom of the form's init() method:

DateEffectivenessPaneController::constructWithForm(
this,
SysEmailTable_ds);

Now when you open the form, it contains an automatically-generated date effectiveness filter at the top:

You have been reading a chapter from
Microsoft Dynamics AX 2012 Development Cookbook
Published in: May 2012
Publisher: Packt
ISBN-13: 9781849684644
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image