In this post, I provide an example of how to import data into a general ledger journal. The included X++ code sample uses the Services framework to transfer and validate the GL data. The specific service used in this example is LedgerGeneralJournalService.
Background
In Microsoft Dynamics AX 2012, services for transferring data have been expanded significantly. As the complexity of the AX data model increases, these services have become more valuable for customization and data migration scenarios. For more information on services, refer to the following section in MSDN:
Services and Application Integration Framework (AIF) [AX 2012]
Code sample
Cut and paste the following code into a new Job in your AX 2012 test environment. You’ll need to set the variables in the declaration section so that they reflect appropriate configuration data for your environment.
static void TestLedgerJournalImport(Args _args) { // Set these variables. LedgerJournalNameId journalName = 'GenJrn'; SelectableDataArea company = 'CEU'; TransDate transactionDate = 30\6\2012; str line1MainAccount = '110110'; str line1FullAccount = '110110--'; str line2MainAccount = '618900'; str line2FullAccount = '618900-10-'; str line2Dimension1Name = 'BusinessUnit'; str line2Dimension1Value = '10'; LedgerGeneralJournalService ledgerGeneralJournalService; LedgerGeneralJournal ledgerGeneralJournal; AfStronglyTypedDataContainerList journalHeaderCollection; LedgerGeneralJournal_LedgerJournalTable journalHeader; AifEntityKeyList journalHeaderCollectionKeyList; RecId journalHeaderRecId; AfStronglyTypedDataContainerList journalLineCollection; LedgerGeneralJournal_LedgerJournalTrans journalLine1; AifMultiTypeAccount journalLine1LedgerDimension; LedgerGeneralJournal_LedgerJournalTrans journalLine2; AifMultiTypeAccount journalLine2LedgerDimension; AifDimensionAttributeValue journalLine2Dim1; AfStronglyTypedDataContainerList journalLine2DimensionCollection; ; ledgerGeneralJournalService = LedgerGeneralJournalService::construct(); ledgerGeneralJournal = new LedgerGeneralJournal(); // Create journal header. journalHeaderCollection = ledgerGeneralJournal.createLedgerJournalTable(); journalHeader = journalHeaderCollection.insertNew(1); journalHeader.parmJournalName(journalName); // Create journal lines. journalLineCollection = journalHeader.createLedgerJournalTrans(); // Line 1 journalLine1 = journalLineCollection.insertNew(1); journalLine1.parmLineNum(1.00); journalLine1.parmCompany(company); journalLine1.parmTransDate(transactionDate); journalLine1.parmAccountType(LedgerJournalACType::Ledger); journalLine1.parmTxt('Test journal transaction'); journalLine1.parmAmountCurDebit(100.00); journalLine1LedgerDimension = journalLine1.createLedgerDimension(); journalLine1LedgerDimension.parmAccount(line1MainAccount); journalLine1LedgerDimension.parmDisplayValue(line1FullAccount); journalLine1.parmLedgerDimension(journalLine1LedgerDimension); // Line 2 journalLine2 = journalLineCollection.insertNew(2); journalLine2.parmLineNum(2.00); journalLine2.parmCompany(company); journalLine2.parmTransDate(transactionDate); journalLine2.parmAccountType(LedgerJournalACType::Ledger); journalLine2.parmTxt('Test journal transaction'); journalLine2.parmAmountCurCredit(100.00); journalLine2LedgerDimension = journalLine2.createLedgerDimension(); journalLine2DimensionCollection = journalLine2LedgerDimension.createValues(); journalLine2Dim1 = new AifDimensionAttributeValue(); journalLine2Dim1.parmName(line2Dimension1Name); journalLine2Dim1.parmValue(line2Dimension1Value); journalLine2DimensionCollection.add(journalLine2Dim1); journalLine2LedgerDimension.parmAccount(line2MainAccount); journalLine2LedgerDimension.parmDisplayValue(line2FullAccount); journalLine2LedgerDimension.parmValues(journalLine2DimensionCollection); journalLine2.parmLedgerDimension(journalLine2LedgerDimension); // Insert records. journalHeader.parmLedgerJournalTrans(journalLineCollection); ledgerGeneralJournal.parmLedgerJournalTable(journalHeaderCollection); journalHeaderCollectionKeyList = LedgerGeneralJournalService.create(ledgerGeneralJournal); journalHeaderRecId = journalHeaderCollectionKeyList.getEntityKey(1).parmRecId(); info(strFmt("LedgerJournalTable.Recid = %1", int642str(journalHeaderRecId))); }
Alternative methods
Becky Newell at Microsoft posted some helpful alternative examples related to general journal imports. The following post shows how to invoke LedgerGeneralJournalService from an external application:
Calling the LedgerGeneralJournal Service in AX 2012
Another example uses the AxLedgerJournalTable and AxLedgerJournalTrans classes to populate the general journal:
Hi
Your articels Are Avery Good.
But what IF The offset account type Are eg. Vendor ?
Br
Jan
LikeLike
Thanks, Jan.
I think it would be possible, but you would have to make some changes. For example, you would use LedgerJournalACType::Vend instead of LedgerJournalACType::Ledger. Also, you would have to set the account to the vendor ID and set the display value to the vendor name.
LikeLike