web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

to get the offsetledgerdimension on ledger journal trans using main account

(0) ShareShare
ReportReport
Posted on by 1,836
hi , everyone , 
 
i was trying to get the LedgerJournalTrans.OffsetLedgerDimension  from main account i tried with helper class but offsetledgerdimension is getting zero so i am not able to post journal can anyone help me on this .
 
 
thanks ,
Regards,
Dinesh
I have the same question (0)
  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at
    What do you mean by "from main account"? Main account is one of the dimensions referenced by LedgerJournalTrans.OffsetLedgerDimension and it can be used on many journal lines. Please tell us what exactly you're trying to achieve.
     
    Also, your statement "I tried with helper class" is extremely vague. Please give us more information.
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi martin thanks for reply 
     
    i was trying to post the journal but i am but due to offset ledger account i am getting error in posting , i need to do the posting by code so i have made main account parameter on the cust parameter form it is default value i am passing from cust parameter but my issue is the offset ledger account is recid and how can i get i am using the main account from main account table i am unable to convert main account to offset ledger dimension , can you please help me on this .below is my code . the code in if is for posting and else is for only inserting lines, i am stuck on posting , i am getting recid from my value for offset ledger dimension is getting zero.
    [Form]
    public class ISLFoCInvoicedSalesOrderForm extends FormRun
    {
        [Control("Button")]
        class Post
        {
            /// <summary>
            ///
            /// </summary>
            public void clicked()
            {
                super();
                int                            recordsCount;
                ISLFoCInvoicedSalesOrder       _iSLFoCInvoicedSalesOrder,iSLFoCInvoicedSalesOrderLoc;
                container                      con;
                Args                           args;
                str                            multiSelectString;
                DialogButton                   Button;
                int                            i;
                RecId                          recid;
                NumberSeq                      numberSeq;
                CustParameters                 custparameter;
                CustTable                     custtable_g;
                Ledgerjournalname              ledgerjournalname;
                LedgerjournalTable             ledgerjournalTable;
                LedgerjournalTrans             ledgerjournalTrans;
                LedgerJournalCheckPost         ledgerJournalCheckPost;
                ;
    
                args = new Args();
    
                recordsCount = ISLFoCInvoicedSalesOrder_ds.recordsMarked().lastIndex(); // gets the total records selected
                _iSLFoCInvoicedSalesOrder = ISLFoCInvoicedSalesOrder_ds.getFirst(1);
                while (_iSLFoCInvoicedSalesOrder)
                {
                    // storing recid of selected field in container
                    con = conIns(con,1,_iSLFoCInvoicedSalesOrder.RecId);
                    // converting container to string with comma separated
                    multiSelectString = con2Str(con,",");
                    _iSLFoCInvoicedSalesOrder = ISLFoCInvoicedSalesOrder_ds.getNext(); // moves to next record
                }
    
                if(con == conNull())
                {
                    Info('please  select  lines to transfer ');
                }
                else
                {
    
                    Button=  Box::okCancel("Do you want to post the journal?",DialogButton::No);
    
                    if (Button == DialogButton::Ok)
                    {
                        select DTJournalName,DTMainAccountId FROM custparameter;
    
                        select ledgerjournalname where ledgerjournalname.JournalName == custparameter.DTJournalName; //use correct payment journal name
    
                        ledgerjournalTable.JournalName = ledgerjournalname.JournalName;
                        ledgerjournalTable.initFromLedgerJournalName();
                        ledgerjournalTable.JournalNum  = JournalTableData::newTable(ledgerjournalTable).nextJournalId();
                        ledgerjournalTable.insert();
    
                        for(i = 1;i<= conLen(con) ;i++)
                        {
                            recid = conPeek(con,i);
    
                            select * from iSLFoCInvoicedSalesOrderLoc
                            where iSLFoCInvoicedSalesOrderLoc.RecId == recid;
    
                            select * from custtable_g
                            where custtable_g.AccountNum == iSLFoCInvoicedSalesOrderLoc.CustAccount;
    
                            numberSeq                               =   NumberSeq::newGetVoucherFromId((ledgerjournalname.NumberSequenceTable));
                            ledgerjournalTrans.Voucher              =   numberSeq.voucher();
                            ledgerjournalTrans.JournalNum           =   ledgerjournalTable.JournalNum;
                            ledgerjournalTrans.AccountType          =   LedgerJournalACType::Cust;
                            ledgerjournalTrans.Company              =   curext();
                            ledgerjournalTrans.parmAccount(custtable_g.AccountNum,ledgerjournalTrans.AccountType);
                            ledgerjournalTrans.initFromCustTable(custtable_g);
                            ledgerjournalTrans.TransDate            =  systemDateGet();
    
                            ledgerjournalTrans.ExchRate             =  ExchangeRateHelper::exchRate(ledgerjournalTrans.CurrencyCode);
                          
    
                            ledgerjournalTrans.Txt                  =   strFmt('Payment for item sale for sales id : %1',iSLFoCInvoicedSalesOrderLoc.SalesId);
    
    
                            ledgerjournalTrans.DefaultDimension         =   custtable_g.DefaultDimension;
                            ledgerjournalTrans.OffsetDefaultDimension   =   custtable_g.DefaultDimension;
    
    
                            LedgerJournalTrans.OffsetLedgerDimension = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber("500002",LedgerJournalACType::Ledger);
                           
                           ledgerJournalTrans.OffsetAccountType        = LedgerJournalACType::Ledger;
          
                            ledgerjournalTrans.TransactionType          =   LedgerTransType::Payment;
                            ledgerjournalTrans.AmountCurCredit          =   iSLFoCInvoicedSalesOrderLoc.InvoiceAmount;
                            ledgerjournalTrans.PaymMode                 =   custtable_g.PaymMode;
                            //ledgerjournalTrans.SettleVoucher            =   SettlementType::SelectedTransact;
                            ledgerjournalTrans.modifiedField(fieldNum(LedgerjournalTrans,PaymMode));
                            ledgerjournalTrans.insert();
    
    
                            //element.settlement(LedgerjournalTrans,ledgerjournalTrans.AmountCurCredit); //look for method
    
                            //Post Journal
                            ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(ledgerjournalTable,NoYes::Yes);
                            ledgerJournalCheckPost.run();
    
                            ttsCommit;
          
                            info(strFmt("Journal %1 created for item sales Id %2 to Student id %3",ledgerjournalTable.JournalNum,iSLFoCInvoicedSalesOrderLoc.SalesId,custtable_g.AccountNum));
    
    
                        }
    
                    }
                    else if(Button == DialogButton::Cancel)
                    {
                        select DTJournalName FROM custparameter;
    
                        select ledgerjournalname where ledgerjournalname.JournalName == custparameter.DTJournalName; //use correct payment journal name
    
                        ledgerjournalTable.JournalName = ledgerjournalname.JournalName;
                        ledgerjournalTable.initFromLedgerJournalName();
                        ledgerjournalTable.JournalNum  = JournalTableData::newTable(ledgerjournalTable).nextJournalId();
                        ledgerjournalTable.insert();
    
                        for(i = 1;i<= conLen(con) ;i++)
                        {
                            recid = conPeek(con,i);
    
                            select * from iSLFoCInvoicedSalesOrderLoc
                            where iSLFoCInvoicedSalesOrderLoc.RecId == recid;
    
                            select * from custtable_g
                            where custtable_g.AccountNum == iSLFoCInvoicedSalesOrderLoc.CustAccount;
    
                            numberSeq                               =   NumberSeq::newGetVoucherFromId((ledgerjournalname.NumberSequenceTable));
                            ledgerjournalTrans.Voucher              =   numberSeq.voucher();
                            ledgerjournalTrans.JournalNum           =   ledgerjournalTable.JournalNum;
                            ledgerjournalTrans.AccountType          =   LedgerJournalACType::Cust;
                            ledgerjournalTrans.Company              =   curext();
                            ledgerjournalTrans.parmAccount(custtable_g.AccountNum,ledgerjournalTrans.AccountType);
                            ledgerjournalTrans.initFromCustTable(custtable_g);
                            ledgerjournalTrans.TransDate            =  systemDateGet();
    
                            ledgerjournalTrans.ExchRate             =  ExchangeRateHelper::exchRate(ledgerjournalTrans.CurrencyCode);
    
                            ledgerjournalTrans.Txt                  =   strFmt('Payment for item sale for sales id : %1',iSLFoCInvoicedSalesOrderLoc.SalesId);
    
    
                            ledgerjournalTrans.DefaultDimension         =   custtable_g.DefaultDimension;
                            ledgerjournalTrans.OffsetDefaultDimension   =   custtable_g.DefaultDimension;
                            ledgerjournalTrans.OffsetLedgerDimension    =  
                                MainAccount::findByMainAccountId(custparameter.DTMainAccountId).RecId;
                            ledgerjournalTrans.TransactionType          =   LedgerTransType::Payment;
                            ledgerjournalTrans.AmountCurCredit          =   iSLFoCInvoicedSalesOrderLoc.InvoiceAmount;
                            ledgerjournalTrans.PaymMode                 =   custtable_g.PaymMode;
                            //ledgerjournalTrans.SettleVoucher            =   SettlementType::SelectedTransact;
                            ledgerjournalTrans.modifiedField(fieldNum(LedgerjournalTrans,PaymMode));
                            ledgerjournalTrans.insert();
                        }
                 
                    }
                }
               
            }
    
        }
    
    }
  • Dineshkarlekar Profile Picture
    1,836 on at
    i have created the field on custparameters , and made join with main account , for the lookup value must be flow from here for offsetledgerdimension.
    so i am trying to get the offsetledgerdimension from main account to make the posting ,
    can u suggest me how can i make the posting .
     
    thanks,
    Regards,
    Dinesh
  • Verified answer
    Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at
    Okay, so you don't want to get  LedgerJournalTrans.OffsetLedgerDimension, you want to assign a value there.
     
    The whole approach looks suspicious; it won't work in many cases, but other dimensions may be required, while you consider just a main account and nothing else.
     
    Anyway, what about doing something like this?
    LedgerDimensionFacade::serviceCreateLedgerDimension(
        LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountId(...));
    Next time, please show us only code relevant to the topic. Almost all code below is not related to getting constructing the offset dimension value and it just complicates the discussion.
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi ,
    Martin ,
    thanks for reply ,
     I have made changes in code , still i am unable to post , same error i am getting value 0 in default ledger dimension . 
     i tried to debug getting the value for account in recid , but value is not getting inserted in to default ledger dimension field.
     numberSeq                               =   NumberSeq::newGetVoucherFromId((ledgerjournalname.NumberSequenceTable));
                            ledgerjournalTrans.Voucher              =   numberSeq.voucher();
                            ledgerjournalTrans.JournalNum           =   ledgerjournalTable.JournalNum;
                            ledgerjournalTrans.AccountType          =   LedgerJournalACType::Cust;
                            ledgerjournalTrans.Company              =   curext();
                            ledgerjournalTrans.parmAccount(custtable_g.AccountNum,ledgerjournalTrans.AccountType);
                            ledgerjournalTrans.initFromCustTable(custtable_g);
                            ledgerjournalTrans.TransDate            =  systemDateGet();
    
                            ledgerjournalTrans.ExchRate             =  ExchangeRateHelper::exchRate(ledgerjournalTrans.CurrencyCode);
                          
    
                            ledgerjournalTrans.Txt                  =   strFmt('Payment for item sale for sales id : %1',iSLFoCInvoicedSalesOrderLoc.SalesId);
    
    
                            ledgerjournalTrans.DefaultDimension         =   custtable_g.DefaultDimension;
                            ledgerjournalTrans.OffsetDefaultDimension   =  0;
    
                            ledgerJournalTrans.OffsetAccountType     = LedgerJournalACType::Ledger;
                            ledgerJournalTrans.OffsetLedgerDimension = LedgerDimensionFacade::serviceCreateLedgerDimension(LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountId(custparameter.DTMainAccountId),custtable_g.DefaultDimension);
                          
                            ledgerJournalTrans.modifiedField(fieldNum(LedgerJournalTrans, OffsetLedgerDimension));
                                 
                            ledgerjournalTrans.TransactionType          =   LedgerTransType::Payment;
                            ledgerjournalTrans.AmountCurCredit          =   iSLFoCInvoicedSalesOrderLoc.InvoiceAmount;
                            ledgerjournalTrans.PaymMode                 =   custtable_g.PaymMode;
                            //ledgerjournalTrans.SettleVoucher            =   SettlementType::SelectedTransact;
                            ledgerjournalTrans.modifiedField(fieldNum(LedgerjournalTrans,PaymMode));
                            ledgerjournalTrans.insert();
    thanks,
    Regard,
    Dinesh
     
  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at
    Please debug the relevant part of your code, which is this one:
    LedgerDimensionFacade::serviceCreateLedgerDimension(LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountId(custParameter.DTMainAccountId), custTable_g.DefaultDimension);
    As you see, you can't fix the problem if you don't know anything about where it occurs. Learning how to debug your code is a key skill you're missing, therefore it's what you should aim to learn.
     
    First of all, verity that the input paramaters have correct values. Then check if getDefaultAccountFromMainAccountId() gives you the right result. If so, debug serviceCreateLedgerDimension() to see where it fails.
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi 
    Martin ,
    Thanks for reply ,
    I have debugged the methods ,getting value in the both method still showing offset ledger dimension  zero , value must pass into it but dont know why ,it is passing . i got value in create ledger dimension .
     public static LedgerDimensionAccount serviceCreateLedgerDimension(
            RecId            _ledgerDimensionId,
            DimensionDefault _dimensionDefault1 = 0,
            DimensionDefault _dimensionDefault2 = 0,
            DimensionDefault _dimensionDefault3 = 0)
        {
            container cachedResult;
            LedgerDimensionAccount createdLedgerDimension;
            LedgerRecId ledgerRecId;
    
            // Add ledger to cache key as default accounts only reference a main account which are only striped by COA, which can cause collisions across ledgers
            ledgerRecId = Ledger::current();
    
            // If no dimension is specified, just return 0
            if (_ledgerDimensionId == 0)
            {
                createdLedgerDimension = 0;
            }
            else
            {
                cachedResult = DimensionCache::getValue(
                    DimensionCacheScope::DefaultingCreateLedgerDimension,
                    [_ledgerDimensionId, ledgerRecId, _dimensionDefault1, _dimensionDefault2, _dimensionDefault3]);
    
                if (cachedResult == connull())
                {
                    cachedResult = [LedgerDimensionFacade::createLedgerDimension(_ledgerDimensionId, _dimensionDefault1, _dimensionDefault2, _dimensionDefault3)];
    
                    DimensionCache::insertValue(
                        DimensionCacheScope::DefaultingCreateLedgerDimension,
                        [_ledgerDimensionId, ledgerRecId, _dimensionDefault1, _dimensionDefault2, _dimensionDefault3],
                        cachedResult);
                }
    
                [createdLedgerDimension] = cachedResult;
            }
    
            return createdLedgerDimension;
        }
    thanks,
    Regards
    Dinesh
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi 
    Martin ,
    Thanks for reply ,
    I have debugged the methods ,getting value in the both method still showing offset ledger dimension  zero , value must pass into it but dont know why ,it is passing . i got value in create ledger dimension . i have declare the variable getting the value in variable . still offset ledger dimension  is getting zero.
    ledgerJournalTrans.OffsetAccountType     = LedgerJournalACType::Ledger;
                            DimensionDynamicAccount        dimensionDynamicAccount ;
    
                            dimensionDynamicAccount  =  LedgerDimensionFacade::serviceCreateLedgerDimension(LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountId(custparameter.DTMainAccountId),custtable_g.DefaultDimension);
                            ledgerJournalTrans.OffsetLedgerDimension = dimensionDynamicAccount ;
    thanks,
    Regards 
    Dinesh
  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at
    Please elaborate what you mean by "it's showing". I don't believe that if the the method returns a (non-zero) number and you assigned the value to ledgerJournalTrans.OffsetLedgerDimension field, the assignment is ignored and the field still contains zero. You must mean something else, but I have no idea what. You'll need to give us a better description of your problem.
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi 
    Martin ,
    Thanks for reply ,
     
    i debugged the code , the value of offset ledger dimension was getting zero due to the modified method which was making its value zero and now , i have change the position so my code is called after modified method , now i am getting desired output , thanks for help .
     
     
    thanks,
    Regards,
    Dinesh.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 584 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 499 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 254 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans