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, ...
Suggested Answer

Fetching vendor posting profile offset account via x++ for invoice registration journal

(0) ShareShare
ReportReport
Posted on by 15

Hi,

For an intercompany invoicing solution I am working on a function to generate an invoice registration journal from a posted intercompany free text invoice. Both companies are on the same F&O instance.

Using below code, I am able to hard code the invoice registration offset account 

private LedgerJournalTrans InterCompFTICreateLedgerJournalTrans(CustInvoiceLine _custInvoiceLine, CustInvoiceTable _custInvoiceTable)
    {
        LedgerJournalTrans		ledgerJournalTrans;
        
        changecompany(vendTable.DataAreaId)
        {
            ledgerJournalTrans.AccountType              = LedgerJournalACType::Vend;
            ledgerJournalTrans.LedgerDimension          = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(vendTable.AccountNum, LedgerJournalACType::Vend);
            ledgerJournalTrans.DocumentDate             = _custInvoiceTable.InvoiceDate;
            ledgerJournalTrans.Invoice                  = _custInvoiceTable.invoiceId;
            ledgerJournalTrans.AmountCurCredit          = _custInvoiceLine.AmountCur;
            ledgerJournalTrans.CurrencyCode             = _custInvoiceTable.CurrencyCode;

            ledgerJournalEngine.ledgerJournalTable(ledgerJournalTable);
            ledgerJournalEngine.initValue(ledgerJournalTrans);

            ledgerJournalTrans.OffsetLedgerDimension	= 5637145838; //hard code of vendor posting profile offset account

            ledgerJournalTrans.insert();
        }

        return LedgerJournalTrans;
    }

However I want to dynamically fetch the main account and dimension for the invoice registration offset, based on the vendor account that is used for the generation of the invoice registration. I tried using below methods, but was not successful.

ledgerJournalTrans.initOffsetDefaultDimension();
ledgerJournalTrans.purchOffsetLedgerDimension();
ledgerJournalTrans.parmOffsetAccount(vendTable.AccountNum,ledgerJournalTrans.OffsetAccountType);
ledgerJournalTrans.parmOffsetLedgerDimension(ledgerJournalEngine.findOffsetLedgerDimension(ledgerJournalTrans));
ledgerJournalTrans.offsetLedgerDimension	= VendLedgerAccounts::purchasingOffsetLedgerDimension(vendTable.AccountNum, VendParameters::find().PostingProfile);
ledgerJournalTrans.findVendTable().purchOffsetLedgerDimension(ledgerJournalTrans.PostingProfile);

Probably I am trying to do this the wrong way as I just started in this role. Please let me know what you think.

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Code Brew,

    Does the vendor belong to a different legal entity than the one you are creating the journal in?

  • André Arnaud de Calavon Profile Picture
    301,020 Super User 2025 Season 2 on at

    Hi Code Brew,

    What is the current result? Have you used the debugger to check what is actually found and used?

  • Code Brew Profile Picture
    15 on at

    Yes, the customer account in the company of the FTI, maps to a vendor account in the company of the invoice registration.

  • Suggested answer
    Code Brew Profile Picture
    15 on at

    After lots of trail and error this seemed to work:

     private LedgerJournalTrans InterCompFTICreateLedgerJournalTrans(CustInvoiceLine _custInvoiceLine, CustInvoiceTable _custInvoiceTable)
        {
            changecompany(vendTable.DataAreaId)
            {
                LedgerJournalTrans          ledgerJournalTrans;
                LedgerJournalEngine         ledgerJournalEngine = LedgerJournalEngine::construct(ledgerJournalName.JournalType);
    
                ledgerJournalEngine.ledgerJournalTable(ledgerJournalTable);
                ledgerJournalEngine.initValue(ledgerJournalTrans);
                ledgerJournalTrans.JournalNum               = ledgerJournalTable.JournalNum;
                ledgerJournalTrans.Company                  = curExt();
                ledgerJournalTrans.AccountType              = LedgerJournalACType::Vend;
                ledgerJournalTrans.DefaultDimension         = LedgerJournalEngine::getAccountDefaultDimension(vendTable.AccountNum, curExt(), LedgerJournalACType::Vend);
                ledgerJournalTrans.modifiedField(fieldNum(LedgerJournalTrans, AccountType));
                ledgerJournalTrans.LedgerDimension          = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(vendTable.AccountNum, LedgerJournalACType::Vend);
                ledgerJournalTrans.DocumentDate             = _custInvoiceTable.InvoiceDate;
                ledgerJournalTrans.Invoice                  = _custInvoiceTable.invoiceId;
                ledgerJournalTrans.Txt                      = _custInvoiceLine.InterCompFTIOffsetTxt;
                ledgerJournalTrans.AmountCurCredit          = _custInvoiceLine.AmountCur;
                ledgerJournalTrans.CurrencyCode             = _custInvoiceTable.CurrencyCode;
                ledgerJournalTrans.TransDate                = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
                ledgerJournalTrans.CurrencyCode             = Ledger::accountingCurrency();
                ledgerJournalTrans.ExchRate                 = ExchangeRateHelper::exchRate(ledgerJournalTrans.CurrencyCode, ledgerJournalTrans.TransDate);
                LedgerDimensionAccount  ledgerDimension     = ledgerJournalEngine.findOffsetLedgerDimension(ledgerJournalTrans);
                ledgerJournalTrans.OffsetAccountType        = LedgerJournalACType::Ledger;
                ledgerJournalTrans.parmOffsetLedgerDimension(ledgerDimension);
                ledgerJournalTrans.LedgerDimensionName      = LedgerJournalTransLedgerDimensionNameHelper::findName(ledgerJournalTrans.DataAreaId, LedgerJournalACType::Vend, ledgerJournalTrans.LedgerDimension);
                ledgerJournalTrans.Approver                 = HcmWorker::findByPerson(DirPartyTable::currentParty()).RecId;
                ledgerJournalTrans.insert();
                
                return LedgerJournalTrans;
            }
    
        }

    The correct use and sequence of ledgerJournalEngine methods were important factors here.

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 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans