Wednesday, 29 January 2014

How To Get Date A Year Before & A Year After in AX 2012

To get date after 1 year from a date in Microsoft Dynamics AX, we can use function "nextYr(date _date)" and we can use function "prevYr(date _date)" to get 1 year before.

Static Void PrevNextYear_test()
{
    date      testDate = str2date("30/1/2014", 123);
    ;
    info(strfmt("This Date : %1, 1 Year After : %2", testDate, nextYr(testDate)));
    info(strfmt("This Date : %1, 1 Year Before : %2", testDate, prevYr(testDate)));
}

If we take start date from user and End Date comes a year after then.
Write Following code in AOT > Forms > FormName > Design > Design > Start Date > modified()
Set Auto Declaration property to Yes.

public boolean modified()
{
    boolean ret;
    ret = super();
    TableName.EndDate = str2date(StartDateControlName.valueStr(), 1234);
    TableName.EndDate = nextYr(TableName.EndDate)-1;
    return ret;
}

No comments:

Post a Comment