Showing posts with label Date effective data patterns. Show all posts
Showing posts with label Date effective data patterns. Show all posts

Tuesday, January 21, 2020

Date effective child form in Dynamics 2012

in a form to display the date effective filter pane you have to add this snippet in the form init method:

DateEffectivenessPaneController::constructWithForm(
        this,
        MYD_ClinicianPositions_ds);

the DateEffectivenessPaneController is responsible of creating all the user interface and the interaction.

image

if you also have a child form which is also date effective and you want it also to be filtered based on the date effective selection on the parent form you can do this:

public class FormRun extends ObjectRun
{
    SysFormSplitter_X verticalSplitter;
    DateEffectivenessPaneController effectivenessPaneController;
}

public void init()
{
    super();
    //Initialize splitter
    verticalSplitter = new SysFormSplitter_X(VSplitter, GridContainer, element, 300);

    //initialize the DateEffectivenessPaneController
    effectivenessPaneController = DateEffectivenessPaneController::constructWithForm(this, MYD_Mentor_ds);
}

then override the executeQuery method of the subform darasource:

public void executeQuery()
{
    FromDate fromDate = dateNull();
    ToDate toDate = dateMax();
    
    TransDate showAsOfDate;
    FormCheckBoxControl showAllCheckbox;
    boolean showAll;
    
    //get the selection from the parent form date effective toolbar
    showAsOfDate = effectivenessPaneController.parmShowAsOfDate();
    showAllCheckbox =  effectivenessPaneController.parmShowAllCheckbox();
    showAll = showAllCheckbox.value();
    
    if (showAll)
        this.query().validTimeStateDateRange(fromDate, toDate);
        
    if (showAsOfDate)
        this.query().validTimeStateAsOfDate(showAsOfDate);

    super();
}

Monday, December 30, 2019

Index consideration for date effective tables

it is a best practice to add ValidTo to the ValidTimeStateKey index
and on the Properties tab (of the ValidTo field in the index) to
select Yes from the Included Column.

image

[see: http://dev.goshoom.net/en/2012/04/included-columns-in-ax2012]

but if it is a clustered index see this:

Performance considerations when designing valid time state tables
To help improve performance of valid time state tables, you should index them correctly.
Valid time state tables are modeled with an alternate key that includes the ValidFrom column.
In some models, the ValidTo column may have also be included in the alternate key,
but this is not necessary for uniqueness, and it should be removed from the alternate key constraint.
If the ValidFrom column is a key column of the clustered index,
the ValidTo column should not also be a key column of the clustered index
.
If the ValidFrom column is a key column of a non-clustered index,
the ValidTo column should be made an included column in the non-clustered index,
which provides coverage for range queries that involve both ValidTo and ValidFrom columns.

for examples see where the index is a clustered index see:
\Data Dictionary\Tables\LogisticsPostalAddress

image

or see
\Data Dictionary\Tables\HcmPositionWorkerAssignment

image

Wednesday, June 12, 2019

Date effective SimpleListDetails form with drop dialog for new record in Dynamics Ax 2012

Create date effective Table

clip_image002

When you set the ValidTimeStateFieldType property it will automatically create the ValidFrom/to fields

clip_image004

 

clip_image005

 

Crete a new form from template SimpleListDetails

Drag the table to the datasource

It will set the date effective query to the default:

clip_image007

Then set the grid datasource and add fields to the grid

clip_image009

Create the groups possibly based on the table groups (otherwise drag fields from the datasource one by one)

clip_image011

clip_image013

clip_image015

 

Add in the init

public void init()
{
    super();
    //Initialize splitter
    verticalSplitter = new SysFormSplitter_X(VSplitter, GridContainer, element, 300);
 
    //For Dates
    //DateEffectivenessPaneController::constructWithForm(this, EF_DateEffectiveTrial1_ds);
 

    //For DateTime
    DateEffectivenessPaneController::constructWithForm(this, EF_DateEffectiveTrial1_ds, true, true, true);
}
 

The form will look like this

clip_image016

 


 

Change the properties of the datasource like this:

clip_image018

 

This allows to change the effective dates manually


 

Create a new Drop Dialog:

Create a new form from template Drop Dialog

 

clip_image020

 

clip_image022

                                                                                                                clip_image023

 

Add those two methods

clip_image024

private ValidFromDateTime getEffectiveDate()
{
    return effectiveDate.dateTimeValue();
}
 
public void init()
{
    ValidFromDateTime           validFromDefaultDate;
    ValidToDateTime             validToDefaultDate;
    Timezone                    userTimeZone;
    EF_DateEffectiveTrial1      common;
 
    super();
 
    common = element.args().record();
    userTimeZone = DateTimeUtil::getUserPreferredTimeZone();
    validFromDefaultDate = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(), userTimeZone); //common.ValidFrom;
    effectiveDate.dateTimeValue(validFromDefaultDate);
 
    //expirationDate.dateValue(validToDefaultDate);
    //set the \Forms\EF_DropDialogEffectiveDate\Designs\Design\[Group:DialogCommit]\[ButtonGroup:ButtonGroup]\CommandButton:OKButton
    //AutoDeclaration = Yes
 
    OKButton.helpText(strFmt("@SYS327712",tableId2pname(common.TableId)));
}
 


 

Create a new menuItem Display

 

clip_image026

 

Create a new DropDialog Button

clip_image027

clip_image028

clip_image029

clip_image030

 

Override the dialogClosed method

clip_image031

 

public void dialogClosed(FormRun _formRun)
{
    Object                          formRunObj;
    ValidFromDateTime               effectiveDate;
    EF_DateEffectiveTrial1          record, recordNew;
    
    super(_formRun);
    
    formRunObj = _formRun;
    
    if (_formRun.closedOk())
    {
        if (formHasMethod(formRunObj, 'getEffectiveDate'))
        {
            effectiveDate = formRunObj.getEffectiveDate();
        }
    
        record = EF_DateEffectiveTrial1_ds.cursor();
        buf2Buf(record, recordNew);
        recordNew.ValidFrom = effectiveDate;
        recordNew.insert();
 
        EF_DateEffectiveTrial1_ds.research(true);
    }
}
 

The form will look like this

clip_image033