Bojensen Blogs

AX WONDERS: Working with the LedgerGeneralJournalService AX 2012

 

As you may well be aware by now, in AX 2012 you can import data by using services. You can use these services to import Customers, GL transactions, Products, etc.
You can learn more about services and AIF in one of my posts called Microsoft Dynamics AX 2012 Services and (Application Integration Framework) AIF architecture , and you might want to take a look into Services and Application Integration Framework .
On this post, I would like to share with you some code to import GL transactions into AX 2012 using the LedgerGeneralJournalService available in AX 2012.

 

static void ImportGLTransWithLedgerGeneralJournalService(Args _args) { // Set these variables. LedgerJournalNameId journalName = 'GenJrn'; SelectableDataArea company = 'CEU'; TransDate transactionDate = 10\10\2012; str line1MainAccount = '256369'; str line1FullAccount = '256369--'; str line2MainAccount = '400090'; str line2FullAccount = '400090-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 journalLine2Dim; AfStronglyTypedDataContainerList journalLine2DimCollection; ; 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('AX Wonders Journal Import test'); journalLine1.parmAmountCurDebit(235.00); // Define Ledger Dimensions 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('AX Wonders Journal Import test'); journalLine2.parmAmountCurCredit(500.00); journalLine2LedgerDimension = journalLine2.createLedgerDimension(); journalLine2DimCollection= journalLine2LedgerDimension.createValues(); journalLine2Dim= new AifDimensionAttributeValue(); journalLine2Dim.parmName(line2Dimension1Name); journalLine2Dim.parmValue(line2Dimension1Value); journalLine2DimCollection.add(journalLine2Dim); // Define Ledger Dimensions journalLine2LedgerDimension.parmAccount(line2MainAccount); journalLine2LedgerDimension.parmDisplayValue(line2FullAcct); journalLine2LedgerDimension.parmValues(journalLine2DimCollection); 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))); }

AX WONDERS: Working with the LedgerGeneralJournalService AX 2012

Comments are closed.