Creating General Ledger journal using document service

Share on linkedin
LinkedIn
Share on twitter
Twitter
Share on facebook
Facebook

This article describes the creation of General Ledger journal through X++ using document service.

There is part in code that will get account structure for specific account, and create ledger dimension for journal line.


[crayon lang=”x++”]
static void ledgerGeneralJournalService(Args _args)
{
LedgerGeneralJournalService service;
LedgerGeneralJournal ledgerGeneralJournal;
LedgerGeneralJournal_LedgerJournalTable ledgerJournalTable;
LedgerGeneralJournal_LedgerJournalTrans ledgerJournalTrans;
LedgerJournalTable ledgerJournal;
Map dimensionValues = new Map(Types::String, Types::String);
AifMultiTypeAccount ledgerDimension;
AfStronglyTypedDataContainerList ledgerJournalTransDimCollection;
AfStronglyTypedDataContainerList ledgerJournalLines;
MainAccount localMainAccount;
RefRecId recId;
DimensionHierarchyId dimensionHierarchyId;
DimensionHierarchy dimHierarchy;
DimensionHierarchyLevel dimHierarchyLevel;
DimensionAttributeValue dimAttrValue;
DimensionAttribute dimAttribute;
LedgerStructure ledgerStructure;
int i;
int numberOfLines = 2;
AifDimensionAttributeValue journalLineDim;
AifEntityKeyList list;
AifEntityKey aifEntityKey;
ledgerJournalCheckPost ledgerJournalCheckPost;

MainAccountNum mainAccountId = ‘112100’;
;

//values for financial dimensions
dimensionValues.insert(‘Department’,’034′);
dimensionValues.insert(‘BusinessUnit’,’006′);
dimensionValue.insert(‘Agreement’,’00004′)

service = LedgerGeneralJournalService::construct();

ledgerGeneralJournal = new ledgerGeneralJournal();

//create journal header
ledgerJournalTable = ledgerGeneralJournal.createLedgerJournalTable().addNew();

ledgerJournalTable.parmJournalName(‘GenJrn’);
ledgerJournalTable.parmName(‘Journal created using document service’);

ledgerJournalLines = ledgerJournalTable.createLedgerJournalTrans();

for(i = 0; i< numberOfLines; i++) { //create journal line ledgerJournalTrans = ledgerJournalLines.addNew(); ledgerJournalTrans.parmAccountType(LedgerJournalACType::Ledger); ledgerJournalTrans.parmTransDate(today() + 2); ledgerJournalTrans.parmTxt(strFmt('Line %1', i)); ledgerJournalTrans.parmCompany('USMF'); //only credit OR debit can be entered ledgerJournalTrans.parmAmountCurCredit(10); //ledgerJournalTrans.parmAmountCurDebit(20); ledgerDimension = ledgerJournalTrans.createLedgerDimension(); ledgerJournalTransDimCollection= ledgerDimension.createValues(); //get account structure localMainAccount = MainAccount::findByMainAccountId(mainAccountId); dimensionHierarchyId = DimensionHierarchy::getAccountStructure(localMainAccount.RecId); select dimHierarchy where dimHierarchy.RecId == dimensionHierarchyId; while select Level from dimHierarchyLevel order by dimHierarchyLevel.DimensionHierarchy, dimHierarchyLevel.Level where dimHierarchy.RecId == dimHierarchyLevel.DimensionHierarchy && dimHierarchy.IsDraft == false && dimHierarchy.IsSystemGenerated == false && dimHierarchy.StructureType == DimensionHierarchyType::AccountStructure join * from dimAttribute where dimAttribute.RecId == dimHierarchyLevel.DimensionAttribute exists join ledgerStructure where ledgerStructure.DimensionHierarchy == dimHierarchy.RecId && ledgerStructure.Ledger == Ledger::current() { //insert values for required financial dimensions if(dimAttribute.Name != 'MainAccount') { journalLineDim = ledgerJournalTransDimCollection.addNew(); journalLineDim.parmName(dimAttribute.Name); journalLineDim.parmValue(dimensionValues.lookup(dimAttribute.Name)); } } ledgerDimension.parmAccount(mainAccountId); ledgerDimension.parmDisplayValue(''); } //create list = service.create(ledgerGeneralJournal); aifEntityKey = list.getEntityKey(1); recId = aifEntityKey.parmRecId(); ledgerJournal = ledgerJournalTable::findByRecId(recId); info(strFmt('Journal %1 created. ', ledgerJournal.JournalNum)); } [/crayon]

You Might Also Like:

Leave a Reply