Wednesday, 27 October 2021

Merge main account with default dimension in D365 fno

Hi Guys,

Merge main account with the default dimension in D365 FnO. we can use the below code to implement it.


transJournal.OffsetLedgerDimension    = LedgerDimensionFacade::ServiceCreateLedgerDimension(CustWriteOffFinancialReasonsSetup.WriteOffLedgerDimension, salesLine.DefaultDimension);


After the merge is completed, a new ledger account combination will be created, This behavior resembles the behavior when default dimensions are merged with each other.


Thanks,


Create customer payment journal from code in D365 Fno

Hi Guys,

This is a very common requirement to create Journal from code(X++) but in D365fno some dimension classes are eliminated so here is the code to create and post a customer payment journal in D365 FnO.


1. Create journal header from click method then call below method to create journal lines.

        public void clicked()

        {

            LedgerJournalTable      ledgerJournalTable;

            CustomerCreditTable  customerCreditTable;

            CreateJournal        createJournal;

            LedgerjournalCheckPost  LedgerjournalCheckPost;

            super();

            try

            {

                ttsbegin;

                ledgerJournalTable.initValue();

                ledgerJournalTable.initFromLedgerJournalName("@Ext:CustPay");

                ledgerJournalTable.JournalNum =  JournalTableData::newTable(ledgerJournalTable).nextJournalId();

                ledgerJournalTable.Name = strFmt("@Ext:WriteOff",DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone()));

                createJournal =  new CreateJournal();


                int numlines = createJournal.createJournalLines(ledgerJournalTable.JournalNum,customerCreditTable.JournalNum);


                if(numlines > 0)

                {

                    ledgerJournalTable.insert();

                    if (ledgerJournalTable)

                    {

                        LedgerjournalCheckPost      =   LedgerjournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::Yes);

                        LedgerjournalCheckPost.runOperation(); 

                    }

                    ttsbegin;

                    select firstonly forupdate customerCreditTable

                        where customerCreditTable.JournalNum == customerCreditTable.JournalNum &&

                        customerCreditTable.IsProcessed == NoYes::No;

                    if (customerCreditTable)

                    {    

                        customerCreditTable.IsProcessed = NoYes::Yes;

                        customerCreditTable.JournalNumRef = ledgerJournalTable.JournalNum;

                        customerCreditTable.doUpdate();

                    }

                    customerCreditTable_ds.research();

                    customerCreditTable_ds.refresh();

                    ttscommit;

                    info(strFmt("@Ext:JVCreated",ledgerJournalTable.JournalNum, numlines));

                }

                ttscommit;

            }

            catch (Exception::Error)

            {

                throw Exception::Error;

            }

        }

2. Call this method in the clicked method to create journal lines as per requirement.

    public int createJournalLines(LedgerJournalId   journalId,LedgerJournalId journalIdOrig)

    {

        LedgerJournalTrans              transJournal;

        RecordInsertList                ledgerJournalTransList;

        NumberSeq                       numberseq;

        Voucher                         voucherNum;

        int                             counter;

        CustomerCreditTable          customerCreditTable;

        //CustInvoiceJour                 custInvoiceJour;

        //SalesLine                       salesLine;

        //LedgerDimensionDefaultAccount   getReasonDim;


        LedgerJournalName ledgerJournalName = ledgerJournalName::find("@Ext:CustPay");

        ledgerJournalTransList = new RecordInsertList(transJournal.TableId);

        numberseq = NumberSeq::newGetVoucherFromCode(NumberSequenceTable::find(ledgerJournalName.NumberSequenceTable).NumberSequence);

        voucherNum = numberseq.voucher();


        while select customerCreditTable where customerCreditTable.IsProcessed == NoYes::No && customerCreditTable.JournalNum == journalIdOrig

        {

            transJournal.clear();

            transJournal.initValue();

            transJournal.JournalNum               =  journalId;

            transJournal.TransDate                =                         DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone());

            transJournal.AccountType              =  LedgerJournalACType::Cust;

            transJournal.LedgerDimension          = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(customerCreditTable.Customer,LedgerJournalACType::Cust);//Journal_Tmp.LedgerDimension;

            transJournal.DefaultDimension         = LedgerDimensionFacade::getDefaultDimensionFromLedgerDimension(transJournal.LedgerDimension);

            transJournal.OffsetAccountType        = customerCreditTable.AccountType;//LedgerJournalACType::Ledger;


            //select firstonly InvoiceId,SalesId from custInvoiceJour

            //    where custInvoiceJour.InvoiceId == customerCreditTable.InvoiceId

            //        join firstonly DefaultDimension from salesLine

            //            where salesLine.SalesId == custInvoiceJour.SalesId;


            //getReasonDim = CustWriteOffFinancialReasonsSetup::findByReasonCode(customerCreditTable.Reason).WriteOffLedgerDimension;

            //transJournal.OffsetLedgerDimension    = LedgerDimensionFacade::ServiceCreateLedgerDimension(getReasonDim, salesLine.DefaultDimension);//22565422738);

            transJournal.OffsetLedgerDimension    = customerCreditTable.LedgerDimension;

            transJournal.CurrencyCode             = customerCreditTable.Currency;

            transJournal.AmountCurCredit          = customerCreditTable.Credit;

            transJournal.MarkedInvoice            = customerCreditTable.InvoiceId;

            transJournal.Txt                      = customerCreditTable.TransactonTxt;

            transJournal.Approved                 = NoYes::Yes;

            transJournal.Approver                 = HcmWorker::userId2Worker(curUserId());

            transJournal.SkipBlockedForManualEntryCheck  = true;

            transJournal.defaultRow();

            if(!transJournal.Voucher)

            {

                transJournal.Voucher                  = voucherNum;

            }

            ledgerJournalTransList.add(transJournal);

            counter++;

        }

        ledgerJournalTransList.insertDatabase();

        numberseq.used();


        return counter;

    }


Thanks,

Code to get default dimension from Ledger dimension in D365 FnO

 Hi Guys,

Fetch default dimensions from Ledger dimension in D365 FnO.

        tmpTable.Dimension = LedgerDimensionFacade::getDefaultDimensionFromLedgerDimension(LedgerjournalTrans.LedgerDimension);


Thanks,





Import General journal from excel in D365 F&O

 Hi Guys, Import General journal from excel in D365 F&O Code:  using System.IO; using OfficeOpenXml; using OfficeOpenXml.ExcelPackage; u...