Monday, 19 August 2013

Posting Journals with X++ - Working with Financial Dimension AX 2012

Let us first go over the changes that have taken place in AX 2012 R2.

Ledger account: In previous versions of Microsoft Dynamics AX the main account and financial dimensions were tracked separately. In AX 2012 the main account and financial dimensions are merged to form one Ledger Account.

DimensionAttributeValueCombination and Ledger Dimension

Unlike previous version all of the Ledger Account combinations that are used in tables, like CustTrans, VendTrans, GeneralJournalAccountEntry have relations to the DimensionAttributeValueCombination.
In AX 2012 all of the ledger accounts are stored in DimensionAttributeValueCombination and the foreign key relation of the RecId is used throughout AX 2012.

DimensionAttributeValueSet and Default Dimension.

DimensionAttributeValueSet is the table that holds all of the dimension in AX 2012. So for instance in the CustTable the field DefaultDimension references the DimensionAttributeValueSet Table.

Now lets get into some Code. The following is method that takes some information and posts a voucher.

The Code in Red is where you will change the values. 

The Code in Green is the main purpose of this tutorial.

We are using the DimensionDefaultingService to combine the Main Account and Default Dimension.

 static void postjournal()  
   LedgerJournalTable                 LedgerJournalTable;  
   LedgerJournalTrans                 LedgerJournalTrans;  
   LedgerJournalTransTaxExtensionIN   LedgerJournalTransTaxExtensionIN;  
   LedgerDimensionAccount             LedgerDim;  
   LedgerDimensionAccount             OffsetledgerDim;  
   LedgerJournalName                  LedgerJournalname;  
   ledgerJournalCheckPost             ledgerJournalCheckPost;  
   NumberSeq                           numSeqVoucher;  
   LedgerJournalTable.JournalName = SalesParameters::find().LedgerJournalName;  
   LedgerJournalName              = LedgerJournalName::find(ledgerJournalTable.JournalName);  
          LedgerJournalTrans.JournalNum            = LedgerJournalTable.JournalNum;  
          Numseqvoucher                            =  NumberSeq::newGetVoucherFromId(LedgerJournalName.NumberSequenceTable, true);  
          LedgerJournalTrans.voucher               = numSeqVoucher.voucher();  
          LedgerJournalTrans.AccountType           = LedgerJournalACType::Cust;  
          ledgerDim                                = DimensionStorage::getDynamicAccount(Your Customer Account Will Go here, LedgerJournalACType::Cust);  
          LedgerJournalTrans.LedgerDimension       = DimensionAttributeValueCombination::find(ledgerDim).Recid;  
          LedgerJournalTrans.DefaultDimension      = Default Dimension;  
          LedgerJournalTrans.AmountCurDebit        = 5000;  
          LedgerJournalTrans.CurrencyCode          = 'INR';  
          LedgerJournalTrans.Txt                   = "Example of Voucher Posting";  
          LedgerJournalTrans.PaymReference         = '000012034';  
          LedgerJournalTrans.OffsetAccountType     = LedgerJournalACType::Ledger;   
          OffsetledgerDim                          = DimensionDefaultingService::serviceCreateLedgerDimension(Ledger Dimensin, Default Dimension);  
          LedgerJournalTrans.OffsetLedgerDimension = OffsetledgerDim;  
          ledgerJournalTrans.Company               = curext();  
          ledgerJournalTrans.TransDate             = systemDateGet();  
          LedgerJournalTrans.AcknowledgementDate   = systemDateGet();
          LedgerJournalTransTaxExtensionIN.LedgerJournalTrans = LedgerJournalTrans.RecId;  
          LedgerJournalTransTaxExtensionIN.TaxInformation_IN  = TaxInformation_IN::findDefaultbyLocation(CompanyInfo::findByCompany_IN().PrimaryAddressLocation).RecId;  
          Numseqvoucher  =  null;   

1 comment:

  1. Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It 's really very nice and Useful post.Thanks
    Tech New