Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Creating journal entry

Posted on by

Hi experts,

I have a table which has all the data i need to perform and get aggregation amt , end objective is to use this aggregate amount & create 1 JE in 1 company having line items corresponding to multiple accounts from multiple company.

Developing  & using custom methods on table i can generate data like below.

pastedimage1600960371339v1.png

After this i need a code/pseduocode which would do the following

1. Create 1 JE in 1 company 

For example je D01 in company D which will never be present in above list of companies

2.Traverse the above structure & create line items in this JE for respective companies & acc# while ignoring 0 amt transactions.

pastedimage1600960507430v3.png

I think key here will be to map the T1 T2 to Ledger dim value of ledger account in that company , is it something which can be managed in Ax directly or i need to create another column in my table & enter full ledgeraccountdim value so as to map T1 to a ledgerdimvalue as they are not stored as values but only as rec id in dimattribute & displayed as complete value only for display purpose.

Thanks 

Mav

  • Mav Profile Picture
    Mav on at
    RE: Creating journal entry

    Gunjan,

    Thanks a lot for your help. My apologies for missing that link on previous post & continuing with system method which indeed becomes an issue when financial dimension is blank , which is weird especially considering that i m checking allow blank values on in the form.

    Neverthless the custom method did fix the issue. Once again thanks expert.

    Thanks

    Mav.

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,417 on at
    RE: Creating journal entry

    Hi Mav,

    I think passing blank values is causing the issue. Can you try this method instead? I am using the earlier post I referred to -

    RecId getLedgerDimension(str _ledgerAccount, str _fDim1, str _fDim2, str _fDim3, str _fdim4, str _fDim5, str _fDim6, str _fDim7, str _fDim8)  
     {  
       DimensionServiceProvider      		DimensionServiceProvider = new DimensionServiceProvider();  
       LedgerAccountContract        		LedgerAccountContract = new LedgerAccountContract();  
       DimensionAttributeValueContract 		ValueContract;  
       List                					ListValueContract = new List(Types::Class);  
       dimensionAttributeValueCombination 	dimensionAttributeValueCombination;  
       DimensionStorage          			dimStorage;  
       
       
       if (_fDim1)  
       {  
         ValueContract = new DimensionAttributeValueContract();  
         ValueContract.parmName('Businessunit') ;  
         ValueContract.parmValue(_fDim1);  
         ListValueContract.addEnd(ValueContract);  
       }
       
       if (_fDim2)  
       {  
         ValueContract = new DimensionAttributeValueContract();  
         ValueContract.parmName('Legalentity') ;  
         ValueContract.parmValue(_fDim2);  
         ListValueContract.addEnd(ValueContract);  
       }
       
       if (_fDim3)  
       {  
         ValueContract = new DimensionAttributeValueContract();  
         ValueContract.parmName('Department') ;  
         ValueContract.parmValue(_fDim3);  
         ListValueContract.addEnd(ValueContract);  
       }
       
       if (_fDim4)  
       {  
         ValueContract = new DimensionAttributeValueContract();  
         ValueContract.parmName('Project') ;  
         ValueContract.parmValue(_fDim4);  
         ListValueContract.addEnd(ValueContract);  
       } 
       
       if (_fDim5)  
       {  
         ValueContract = new DimensionAttributeValueContract();  
         ValueContract.parmName('Shipment') ;  
         ValueContract.parmValue(_fDim5);  
         ListValueContract.addEnd(ValueContract);  
       }
       
       if (_fDim6)  
       {  
         ValueContract = new DimensionAttributeValueContract();  
         ValueContract.parmName('Customer') ;  
         ValueContract.parmValue(_fDim6);  
         ListValueContract.addEnd(ValueContract);  
       }
       
       if (_fDim7)  
       {  
         ValueContract = new DimensionAttributeValueContract();  
         ValueContract.parmName('COntract') ;  
         ValueContract.parmValue(_fDim7);  
         ListValueContract.addEnd(ValueContract);  
       }
       
       if (_fDim8)  
       {  
         ValueContract = new DimensionAttributeValueContract();  
         ValueContract.parmName('Location') ;  
         ValueContract.parmValue(_fDim8);  
         ListValueContract.addEnd(ValueContract);  
       }
       
       LedgerAccountContract.parmMainAccount(_ledgerAccount);  
       LedgerAccountContract.parmValues(ListValueContract);  
       
       dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);  
       dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
       
       return dimensionAttributeValueCombination.RecId;  
     } 

  • Mav Profile Picture
    Mav on at
    RE: Creating journal entry

    HI Gunjan

    Here is the snippet with my comments on FAIL case & Pass/working case also showing at which line it is failing in both my custom class & system class.

     
      _dimvalue  = "MAcct-Fdim2-Fdim3-Fdim4----Fdim7-Fdim8";          // FAILS as Fdim 5,6, & 7 are blank  FAILS at line 16 in createJE() which it recives as ERROR at line 78 for getLedgerAccountId(container _dimensionValue) because "" does not exist in dimattributevalue table , however that should not be the case as Dimension was set to allow blanks yes in COA as shown in pic in previous post.
      -dimvalue = "Macct-Fdim2-Fdim3-Fdim4-Fdim5-Fdim6-Fdim7-Fdim8";  //Works as i m providing value for all FDIMS
      
       public static createJELineitems(str _dimvalue)
     {
        
         dimcon = str2con(_dimvalue, ledgerAccountDelimiter, false);
                       
         _acctPattern        =  [_ledgerJournalTrans.LedgerCode(),_ledgerJournalTrans.LedgerCode(),9,'MainAccount',conPeek(dimcon,1),'Fdim1',conPeek(dimcon,2),
            'Fdim2',conPeek(dimcon,3),'Fdim3',conPeek(dimcon,4),'Fdim4',conPeek(dimcon,5),'Fdim5',conPeek(dimcon,6),'Fdim6',conPeek(dimcon,7),'Fdim7',conPeek(dimcon,8),'Fdim8',conPeek(dimcon,9)];
            
        _offSetAcctPattern  = [_ledgerJournalTrans.OffsetLedgerCode(),_ledgerJournalTrans.OffsetLedgerCode(),0];
    
        ledgerJournalTrans.AccountType            = LedgerJournalACType::Ledger;
        ledgerJournalTrans.LedgerDimension        = AxdDimensionUtil::getLedgerAccountId(_acctPattern);
        ledgerJournalTrans.TransDate              = _ledgerJournalTrans.TransactionDate();
        
        }
        
        
        
        
        System class AxdDimensionUtil
        
        public static recId getLedgerAccountId(container _dimensionValue)
    {
        LedgerAccountContract           ledgerAccountContract;
        DimensionServiceProvider        dimensionServiceProvider;
        DimensionStorage                dimensionStorage;
        MainAccountNum                  mainAccountId;
        int                             collectionCount, collectionIndex, containerElementIndex;
        str                             displayValue, attributeName, attributeValue;
        DimensionAttribute              dimensionAttribute;
        DimensionAttributeValue         dimensionAttributeValue;
    
        // Initialize variables needed for this method.
        dimensionStorage = DimensionStorage::construct(0, LedgerDimensionType::Account);
        dimensionServiceProvider = new DimensionServiceProvider();
        ledgerAccountContract = new LedgerAccountContract();
        ledgerAccountContract.parmValues(new List(Types::Class));
        containerElementIndex = 1;
    
        // At this point we need to read the values from the passed in container and use them to build the
        // list of values needed by the DimensionServiceProvided.
    
        // Get displayValue.
        displayValue = conPeek(_dimensionValue, containerElementIndex);
        containerElementIndex  ;
    
        // Get MainAccountId value.
        mainAccountId = conPeek(_dimensionValue, containerElementIndex);
        ledgerAccountContract.parmMainAccount(mainAccountId);
        containerElementIndex  ;
    
        // Validate that the MainAccount exists.
        AxdDimensionUtil::validateMainAccount(mainAccountId);
    
        // Get Attribute Name/ Attribute Value pair count.
        collectionCount = conPeek(_dimensionValue, containerElementIndex);
        containerElementIndex  ;
    
        // We need to load the list ledgerAccountContract.parmValues() so we can get a dimension storage instance built.
        for (collectionIndex = 1; collectionIndex <= collectionCount; collectionIndex  )
        {
            // Get attribute name
            attributeName = conPeek(_dimensionValue, containerElementIndex);
            containerElementIndex  ;
    
            // Validate the Financial Dimenion that was passed in.
            dimensionAttribute = AxdDimensionUtil::validateFinancialDimension(attributeName);
    
            // Get attribute value
            attributeValue = conPeek(_dimensionValue, containerElementIndex);
            containerElementIndex  ;
    
            // Validate the Financial Dimenion Value that was passed in.
            dimensionAttributeValue = AxdDimensionUtil::validateFinancialDimensionValue(dimensionAttribute, attributeValue);
    
            // Add the Dimension Name and Value to the Values list in the contract.
            ledgerAccountContract.parmValues().addEnd(AxdDimensionUtil::fillDimensionAttributeValueContract(attributeName,attributeValue));
        }
    
        dimensionStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(ledgerAccountContract);
    
        return dimensionStorage.save();
    }
    

    Thanks
    Mav

  • Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,417 on at
    RE: Creating journal entry

    Hi Mav,

    Please share your code where you are passing values to this method.

  • Mav Profile Picture
    Mav on at
    RE: Creating journal entry

    Finally was able to understand and make below FOR loop working to get finacial dim attribute name & attribute value.

    However the code still errors out for dimension having blank values at red line shown in pic below which is weird because in COA  the dimension is set to Allow blanks

    Any ideas to fix this?

    pastedimage1601482079312v1.png

    Pic showing allow blanks for financcial dim in COA structure form.

    pastedimage1601482262614v2.png

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,417 on at
    RE: Creating journal entry

    Hi Mav,

    Since the account is being provided in a particular format, Can you segregate each of the dimensions and store the values in a variable? You can then create the ledger dimension and assign it to LedgerJournalTrans.LedgerDimension / LedgerJournalTrans.OffsetLedgerDimension fields.

    Please check the code here.

  • Mav Profile Picture
    Mav on at
    RE: Creating journal entry

    Hi Dr,

     Can you share an example of how to take full ledger dim value and then use that in account field of ledger journal line items?

    The requirement is very clear that user will provide full ledger dimension value and Ax should create journal line items with account field showing full ledger dim instead of just main account.

    With above code  I am able to create JE line items however it shows only main account number under accounts of JE line items, hence it  fails my cause as the requirement  is to create JE line item with full ledger dim value showing under accounts field of JE line items.

    Thanks

    Mav

  • Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: Creating journal entry

    Hi Mav,

    I am not sure whether you have to code all of that stuff.

    There are some 'hidden' features available in the COA and other setup forms in AX2012 that might be able to create the extra line automatically without coding.

    Yet, we would need a better understand of what these extra lines shall be used for and what the purpose of that extra lines is.

    Best regards,

    Ludwig

  • Mav Profile Picture
    Mav on at
    RE: Creating journal entry

    ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
        
      statick job1()
      {
         Ledgerjournaltrans ledgerjournaltrans;
         str 50 dim value,ledgerAccountDelimiter;
         MyJECreateutil      syncUtil            = new MyJECreateutil();
         MyJEDatacontract   myDc     = new MyJEDatacontract();
         List               transacitonList       = new List(Types::Class);
    
    
        dimvalue = "920000-005-Cma-02----Contract_1-";
        ledgerAccountDelimiter =  SystemParameters::getChartOfAccountsDelimiter();
        dimvaluecon = str2con(dimvalue, ledgerAccountDelimiter, false);
    
        ledgerJournalTrans.LedgerDimension = AxdDimensionUtil::getLedgerAccountId(dimvaluecon);  ERRORS out here because of reasons stated below
        
        
        /* Working code , working i.e. creating journal ledger & journal line tems
        //WOrking code begin
        
     
        myDc.LedgerCode("111001");
        myDc.OffsetLedgerCode("999999");
        myDc.TransactionCurrencyAmount(1);
        myDc.TransactionDate(01\09\2020);
    
        transacitonList.addEnd(myDc);
    
        myDc = new EVA_UltiproCreateJEDC();
    
        myDc.LedgerCode("111001");
        myDc.OffsetLedgerCode("999999");
        myDc.TransactionCurrencyAmount(2);
        myDc.TransactionDate(01\09\2020);
    
        transacitonList.addEnd(myDc);
    
        
        syncUtil.CreateGeneralJournal("Myjournalname", "OB Transfer", transacitonList);
    
       info("Created General Journal !");  
       //Working code end  */
        
        
        
        
        }

    Hi,

    Unable to share full project , however sharing the code for test job for core issue & reference used to create utilities can be found here 

    Above is sample test job showing where it fails at line 13 because it is unable to populate attribute names  in below class  I understand that below system class is trying to look everything in 1 container which is not easily doable.

    Main objective still remains the same  - User provides a full ledger dimension , details of which shared above , need to create a ledgher journal line item with that full dimension showing in account number.

    pastedimage1601426941759v1.png

    Thanks

    Mav

  • Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,417 on at
    RE: Creating journal entry

    Hi Mav,

    Could you please share the code you have till now?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,672 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans