Create Fixed Asset Journal using X++
In this blog article, we will see how we can create Fixed Asset Journal using X++.
Write below code to create Journal Header in LedgerJournalTable Table and Lines record in LedgerJournalTrans and LedgerJournalTrans_Asset Tables.
public void createFixedAssetJournal() { LedgerJournalTable ledgerJournalTable; LedgerJournalTrans ledgerJournalTrans; LedgerJournalTrans_Asset ledgerJournalTrans_Asset; Assettable assetTable; ledgerJournalTable.initValue(); ledgerJournalTable.JournalNum = JournalTableData::newTable(ledgerJournalTable).nextJournalId(); ledgerJournalTable.Posted = NoYes::No; ledgerJournalTable.JournalName = 'ACQUI'; ledgerJournalTable.JournalType = LedgerJournalType::Assets; ledgerJournalTable.initFromLedgerJournalName(ledgerJournalTable.JournalName); ledgerJournalTable.insert(); ledgerjournalTrans.initValue(); ledgerJournalTrans.CurrencyCode = Ledger::accountingCurrency(CompanyInfo::find().RecId); ledgerJournalTrans.AccountType = LedgerJournalACType::FixedAssets; ledgerJournalTrans.TransactionType = LedgerTransType::FixedAssets; ledgerJournalTrans.Approved = NoYes::Yes; ledgerJournalTrans.Approver = HcmWorker::userId2Worker(curuserid()); ledgerJournalTrans.LineNum = LedgerJournalTrans::lastLineNum(ledgerJournalTrans.JournalNum) + 1; ledgerJournalTrans.TransDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()); ledgerJournalTrans.LedgerDimension = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(AssetTable.AssetId,LedgerJournalACType::FixedAssets); ledgerJournalTrans.accountName(); ledgerJournalTrans.AmountCurDebit = '45'; ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger; ledgerJournalTrans.OffsetLedgerDimension = ledgerJournalTrans.getOffsetLedgerDimensionForLedgerType(AssetLedgerAccounts::assetOffsetLedgerDimension(AssetTable.AssetId, AssetTable.assetBookCurrent().BookId, AssetTransType::Acquisition),curExt()); ledgerJournalTrans.insert(); ledgerJournalTrans_Asset.initValue(); ledgerJournalTrans_Asset.RefRecId = ledgerJournalTrans.RecId; ledgerJournalTrans_Asset.AssetId = assetTable.assetId; ledgerJournalTrans_Asset.TransType = AssetTransTypeJournal::Acquisition; ledgerJournalTrans_Asset.BookId = AssetTable.assetBookCurrent().BookId; ledgerJournalTrans_asset.insert(); ttsbegin; LedgerJournalTable.selectForUpdate(true); LedgerJournalTable.numOfLines = LedgerJournalTable.numOfLines(); LedgerJournalTable.update(); ttscommit; }