Monday 23 January 2017

X++ code to copy Ledger from company (A) to Company (B)


public void copyLedgerSetup()
{
    Ledger   fromLedger = Ledger::findByLegalEntity(CompanyInfo::findDataArea(fromCompany).RecId);
    Ledger   toLedger   = Ledger::findByLegalEntity(CompanyInfo::findDataArea(toCompany).RecId);
    LedgerStructure fromLedgerStructure, toLedgerStructure;
    LedgerGainLossAccount fromLedgerGainLossAccount, toLedgerGainLossAccount;

    if (fromLedger && !toLedger)
    {
        toLedger.data(fromLedger);
        toLedger.PrimaryForLegalEntity = CompanyInfo::findDataArea(toCompany).RecId;
        toLedger.Name = toCompany;
        toLedger.doInsert();

        while select fromLedgerStructure
            where fromLedgerStructure.Ledger == fromLedger.RecId
        {
            toLedgerStructure.data(fromLedgerStructure);
            toLedgerStructure.Ledger = toLedger.RecId;
            toLedgerStructure.insert();
        }

        while select fromLedgerGainLossAccount
            where fromLedgerGainLossAccount.Ledger == fromLedger.RecId
        {
            toLedgerGainLossAccount.data(fromLedgerGainLossAccount);
            toLedgerGainLossAccount.Ledger = toLedger.RecId;
            toLedgerGainLossAccount.insert();
        }
    }
}

No comments:

Update NuGet package to new MS D365FO version

1. Import the NuGet package files from LCS for that particular version please take the PU version files only. a. Goto LCS-->Asset Libra...