How can I code in X++ to copy a Fiscal Year to all companies from a base company thats been set up?

StackOverflow https://stackoverflow.com//questions/24010046

  •  21-12-2019
  •  | 
  •  

Question

We are running Dynamics AX2012 R2 CU7 and we coded:,

"copy a Fiscal Year to all companies from a base company that's already been set up",

feature for our source system which was Dynamics AX 2009. The structures in Dynamics AX 2012 R2, CU7 is so different that I don't know how to go about achieving the same functionality through X++ coding.

Original Code:

void clicked()
{
  ModulePeriodStat ledger, bank, cust, asset, invent, prod, proj, purch, sales, tax, vend ;
    PeriodEnd        period;
    LedgerPeriod     ledgerPeriod2;
    CompanyInfo      companyInfo;
    Dialog                  dlg;
    ;

    super();

    dlg = new Dialog("Confirm: ");
    dlg.addText("You will create these periods in all companies "+date2str(period,321,2,2,2,2,4));
    dlg.run();
    if ((dlg.closedOk()))
    {
    ttsbegin;

    while select crosscompany companyInfo
    {
    if (companyInfo.dataAreaId != 'ct11' && companyInfo.dataAreaId != 'ct13' && companyInfo.dataAreaId != 'md11' && companyInfo.dataAreaId != 'mf11')
    changecompany(companyInfo.dataAreaId)
    {
        ledgerPeriod2 = null;
    while select forUpdate ledgerPeriod     // where (ledgerPeriod.PeriodEnd == period)
    {
        ledger = ledgerPeriod.StatusLedger;
        bank = ledgerPeriod.StatusBank;
        cust = ledgerPeriod.StatusCust;
        asset = ledgerPeriod.StatusFixedAsset;
        invent = ledgerPeriod.StatusInvent;
        prod = ledgerPeriod.StatusProd;
        proj = ledgerPeriod.StatusProj;
        purch = ledgerPeriod.StatusPurch;
        sales = ledgerPeriod.StatusSalesOrder;
        tax = ledgerPeriod.StatusTax;
        vend = ledgerPeriod.StatusVend;
        period = ledgerPeriod.PeriodEnd;
        ledgerPeriod2.PeriodStart = ledgerPeriod.PeriodStart;
        ledgerPeriod2.PeriodCode = ledgerPeriod.PeriodCode;
        ledgerPeriod2.PeriodEnd = period;
        ledgerPeriod2.PeriodStatus = ledgerPeriod.PeriodStatus;
        ledgerPeriod2.Commentaries = ledgerPeriod.Commentaries;
        ledgerPeriod2.StatusLedger = ledger;
        ledgerPeriod2.StatusBank = bank;
        ledgerPeriod2.StatusCust = cust;
        ledgerperiod2.StatusFixedAsset = asset;
        ledgerPeriod2.StatusInvent = invent;
        ledgerPeriod2.StatusProd = prod;
        ledgerperiod2.StatusProj = proj;
        ledgerPeriod2.StatusPurch = purch;
        ledgerperiod2.StatusSalesOrder = sales;
        ledgerPeriod2.StatusTax = tax;
        ledgerperiod2.StatusVend = vend;
        try
        {
        ledgerperiod2.insert();
        }
        catch (Exception::DuplicateKeyException)
        {
            period = period;
            print('Problem encountered with company: '+companyinfo.dataAreaId);
        }
    }
    }
    }
    ttscommit;
    box::info('Periods Created Successfully');
    }
}
Was it helpful?

Solution

You do not need such a functionality in AX 2012.

From the white paper (page 735) linked by FH-Inway:

In Microsoft Dynamics AX 2009, the LedgerPeriod table and form are used to create and maintain the fiscal periods for a company.

Reason for deprecation: Global organizations operate as different legal entities in different geographical areas. However, they share a lot of data, such as charts of accounts, currencies, exchange rates, and calendars. Defining this reference and master data once and sharing it across legal entities reduces the cost of maintaining such data across the organization. However, ledger periods, and the associated AssetCalendar tables, did not provide sufficient support for this scenario and have been replaced with more robust shared fiscal calendars.

Replaced by another feature: The feature is no longer available and has been replaced with shared fiscal calendars.

Setup your shared fiscal calendar in General Ledger\Setup\Fiscal calendar.

Then select that fiscal calendar in Genreral Ledger\Setup\Ledger.

Update 2:

The closing of ledger periods is done in the Ledger Calendar. The open/closed status of a period is stored in the table LedgerFiscalCalendarPeriod. Although it is global, it is linked to the Ledger table of which there is one per company.

Thus you have no need for any customization regarding ledger periods.

OTHER TIPS

You could take a look at the white papers that describe the changes from AX 2009 to 2012. At least in New, Changed, and Deprecated Features for Microsoft Dynamics AX 2012 you will find multiple references to changes regarding fiscal years. You can also check out About fiscal calendars, fiscal years, and periods [AX 2012] on TechNet which is linked in the white paper.

What I was able to get from skimming through the information is that the data in the tables for fiscal years is now available in all companies, so no need to copy fiscal years into other companies. It seems you can define in the ledger which fiscal year a legal entity/company should use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top