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

 

No comments:

Post a Comment