Search code examples
axaptamicrosoft-dynamicsdynamics-ax-2012dynamics-ax-2012-r3

Bring Vendor Name as a column in LedgerTransAccount form


I am trying to bring the vendor name on each line in the TransAccountForm.

I have written a small piece of code which gets the vendor name when LedgerDimension from LedgerJournalTrans is available:

static void GetVendorName(Args _args)
{
   CustAccount custAccount;
   VendTable vendTable;

   LedgerJournalTrans ledgerJournalTrans;

   while select ledgerJournalTrans
   {
       if (ledgerJournalTrans.AccountType == LedgerJournalACType::Vend)
       {
           custAccount = DimensionStorage::ledgerDimension2AccountNum(LedgerJournalTrans.LedgerDimension);

           select firstOnly vendTable
               where vendTable.AccountNum == custAccount;

            info(strFmt("Vendor Name: %1, Voucher: %2", DirPartyTable::getName(vendTable.Party), ledgerJournalTrans.Voucher));
        }
    }
}

But how can I get to run this code in order to bring that new column with the vendor name?

Thanks to Jan B. Kjeldsen I got to this solution:

One of the data source in LedgerTransAccount is GeneralJournalEntry on wich i add the display method. With the help of SubLedgerVoucher i am able to get one line from LedgerJournalTrans.

public display Name VendorName()
{
    Name ret;
    LedgerJournalTrans ledgerJournalTrans;

    select firstFast firstOnly ledgerJournalTrans
        where ledgerJournalTrans.Voucher == this.SubledgerVoucher && 
            ledgerJournalTrans.TransDate == this.AccountingDate;

   ret = ledgerJournalTrans.AccountType == LedgerJournalACType::Vend ?
               vendTable::find(DimensionStorage::ledgerDimension2AccountNum
                (ledgerJournalTrans.LedgerDimension)).name() : '';

   return ret;
}

After this, I just drag and drop this method on my form's grid.


Solution

  • You can add a display method to the ledgerJournalTrans table:

    [SysClientCacheDataMethodAttribute(true)]
    display VendName vendName()
    {
        return this.AccountType == LedgerJournalACType::Vend ? vendTable::find(DimensionStorage::ledgerDimension2AccountNum(this.LedgerDimension)).name() : '';
    }
    

    A one-liner.