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:

Import and Export file from BLOB storage Account(Azure) in D365 F&O using X++

  Import and Export file from BLOB storage Account in D365 F&O using X++ Import: /// <summary> /// MKInventQualityOrderLineService...