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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

How to read data from custom Table

(0) ShareShare
ReportReport
Posted on by 390

Hi Team,

I am using below code to creating VendorPayment Journal Thru X++ code. Its creating payment Journal as expected but my requirement is need to read data from custom Table and based on that data only create vendor payment Journal:

here is code:

static void VendPaym(Args _args)
{
AxLedgerJournalTable journalTable; // class
AxLedgerJournalTrans journalTrans,journalTrans1; // class
container acctPattern;
container offSetAcctPattern;
LedgerJournalTable ledgerJournalTable; // table
ledgerJournalCheckPost ledgerJournalCheckPost;// table
;
journalTable = new AxLedgerJournalTable();
journalTrans = new AxLedgerJournalTrans();
//Journal Name
journalTable.parmJournalName("VendPay");
journalTable.parmJournalType(LedgerJournalType::Payment);
journalTable.save();
journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
journalTrans.parmTransDate(systemDateGet());
journalTrans.parmCurrencyCode("USD");
journalTrans.parmMgCurrencyCode(JournalTable.mgledgerJournalTable().CurrencyCode);
journalTrans.parmAmountCurDebit(1200);
journalTrans.parmAccountType(LedgerJournalACType::Vend);
journalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount('1001',LedgerJournalACType::Vend));

journalTrans.save();

journalTrans1 = new AxLedgerJournalTrans();
journalTrans1.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
journalTrans1.parmAccountType(LedgerJournalACType::Ledger);
journalTrans1.parmLedgerDimension(22565454369);
journalTrans1.parmCurrencyCode("USD");
journalTrans1.parmAmountCurCredit(1200);
journalTrans1.save();

ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(journalTable.ledgerJournalTable(),NoYes::No);
ledgerJournalCheckPost.run();
info(strFmt("Journal No. %1.", journalTable.ledgerJournalTable().JournalNum));
}

my custom Table is MG_LedgerJournalTable which have currency field and Value is INR.

My requirement is need to pick Currency code INR from MG_LedgerJournalTable and create the Journal and once completed pick for next record.

Can any one give the solution ?  

Thnaks...

Ramesh Muthyala

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    You can iterate your table with:

     MG_LedgerJournalTable myTable;
     
     while select myTable
     {
        // Put here the code to create journal lines
        // you can access the currency field by myTable.Currency
     }

  • Ramesh Muthyala Profile Picture
    390 on at

    Hi Nikolaos,

    Thanks for reply..

    I was used below code to read data :

    MG_LedgerJournalTable  mgLedgerJournalTable;

     while select mgLedgerJournalTable

         {

       ledgerJournalTable.clear();

       ledgerJournalTrans.CurrencyCode = mgLedgerJournalTable.CurrencyCode;

       ledgerJournalTrans.insert();

        ledgerJournalTrans.insert();

        LedgerJournalTrans.update();

       }

    But still Taking USD by default. here my table value is INR.

    below the reference:

    pastedimage1578399937142v1.png

  • nmaenpaa Profile Picture
    101,166 Moderator on at

    Is that your full code? It's hard to believe that the code above would create the journal that you show in your picture. Could you please share your full code?

  • Ramesh Muthyala Profile Picture
    390 on at

    Hi Nik,

    below is full code:

    public static void VendPaymJournalCreate(Args _args)

    {

    AxLedgerJournalTable journalTable; // class

    AxLedgerJournalTrans journalTrans,journalTrans1; // class

    GetInvoice getInvoice;

    container acctPattern;

    container offSetAcctPattern;

    LedgerJournalTable ledgerJournalTable; // table

    ledgerJournalCheckPost ledgerJournalCheckPost;// table

    MG_LedgerJournalTable  mgLedgerJournalTable;

    LedgerJournalTrans  ledgerJournalTrans;

    ;

    journalTable = new AxLedgerJournalTable();

    journalTrans = new AxLedgerJournalTrans();

    getInvoice  = new GetInvoice();

    //Journal Name

    journalTable.parmJournalName("VendPay");

    journalTable.parmJournalType(LedgerJournalType::Payment);

    journalTable.save();

    journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);

           while select mgLedgerJournalTable

         {

       ledgerJournalTable.clear();

       ledgerJournalTrans.CurrencyCode = mgLedgerJournalTable.CurrencyCode;

       ledgerJournalTrans.insert();

       info(strFmt("Invoice: %1", ledgerjournalTrans.CurrencyCode));

               ledgerJournalTrans.insert();

               LedgerJournalTrans.update();

       }

    journalTrans.parmTransDate(systemDateGet());

     journalTrans.parmAmountCurDebit(journalTable.mgledgerJournalTable().JournalTotalDebit);

    journalTrans.parmAccountType(LedgerJournalACType::Vend);

    journalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount("1002",LedgerJournalACType::Vend));

    journalTrans.save();

    journalTrans1 = new AxLedgerJournalTrans();

    journalTrans1.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);

    journalTrans1.parmAccountType(LedgerJournalACType::Ledger);

    journalTrans1.parmLedgerDimension(22565454369);

    journalTrans1.parmAmountCurCredit(journalTable.ledgerJournalTable().JournalTotalCredit);

    journalTrans1.save();

    ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(journalTable.ledgerJournalTable(),NoYes::NO);

    ledgerJournalCheckPost.run();

    info(strFmt("Journal No. %1.", journalTable.ledgerJournalTable().JournalNum));

    }

  • Verified answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    If you look at your code, you are attempting to insert ledgerJournalTrans records that have only the CurrencyCode field set up. Obviously such records will not show up on any journal.

    Your code is somehow very confusing.

    Anyway I modified it a bit, and now it should create one payment journal for every record in MG_LedgerJournalTable table, using the currency code from MG_LedgerJournalTable:

        static void VendPaym(Args _args)
        {
        AxLedgerJournalTable journalTable; // class
        AxLedgerJournalTrans journalTrans,journalTrans1; // class
        container acctPattern;
        container offSetAcctPattern;
        LedgerJournalTable ledgerJournalTable; // table
        ledgerJournalCheckPost ledgerJournalCheckPost;// table
        MG_LedgerJournalTable mgLedgerJournalTable;
        ;
        
        while select mgLedgerJournalTabe
        {
            journalTable = new AxLedgerJournalTable();
            journalTrans = new AxLedgerJournalTrans();
            //Journal Name
            journalTable.parmJournalName("VendPay");
            journalTable.parmJournalType(LedgerJournalType::Payment);
            journalTable.save();
            journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
            journalTrans.parmTransDate(systemDateGet());
            journalTrans.parmCurrencyCode(mgLedgerJournalTabe.CurrencyCode);
            journalTrans.parmMgCurrencyCode(JournalTable.mgledgerJournalTable().CurrencyCode);
            journalTrans.parmAmountCurDebit(1200);
            journalTrans.parmAccountType(LedgerJournalACType::Vend);
            journalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount('1001',LedgerJournalACType::Vend));
            journalTrans.save();
            journalTrans1 = new AxLedgerJournalTrans();
            journalTrans1.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
            journalTrans1.parmAccountType(LedgerJournalACType::Ledger);
            journalTrans1.parmLedgerDimension(22565454369);
            journalTrans1.parmCurrencyCode(mgLedgerJournalTabe.CurrencyCode);
            journalTrans1.parmAmountCurCredit(1200);
            journalTrans1.save();
            ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(journalTable.ledgerJournalTable(),NoYes::No);
            ledgerJournalCheckPost.run();
            info(strFmt("Journal No. %1.", journalTable.ledgerJournalTable().JournalNum));
        }
        }

  • Ramesh Muthyala Profile Picture
    390 on at

    Thanks Nik,

    Its created now..

    Thanks

    Ramesh Muthyala

  • nmaenpaa Profile Picture
    101,166 Moderator on at

    Hi Ramesh, glad to hear that it's now working. Could you please mark the helpful answer(s) as verified? Thanks!

  • Ramesh Muthyala Profile Picture
    390 on at

    Hi Nik,

    its working as expected now 

    Thanks for your help..

    Thanks,

    Ramesh Muthyaka.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 617

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 461 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 298 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans