Friday 31 July 2015

How to get Cust account or Vend account from ledgerJournalTrans?

LedgerJournalTrans may keep information about few types of account.
Two of them may be information about customer and vendor account.

There are two ways to find a CustTable record or VendTable record from ledgerJournalTrans.

First option:
Harder but it will show how does it work.

At the beginning it's good to know that this information is stored in LedgerJournalTrans in field LedgerDimension

So before you'll start searching vendor or customer, it would be good to check what type of account is stored in LedgerJournalTrans.
You will now that from field AccountType.

LedgerDimension stores an info about record of table DimensionAttributeValueCombination
And this last table has a field which may be interesting for us: DisplayValue

So, let's make a job which will give us a record from CustTable or from VendTable

static void accountHardWay(Args _args)
{
    LedgerJournalTrans                      ledgerJournalTrans;
    DimensionAttributeValueCombination      combination;
    CustTable                               custTable;
    VendTable                               vendTable;
    
    //I assume that we already have a record 
    //from ledgerJournalTrans
    
    combination = DimensionAttributeValueCombination::find(ledgerJournalTrans.LedgerDimension);
    
    if (combination)
    {
        if (ledgerJournalTrans.AccountType == LedgerJournalACType::Cust)    
        {
            custTable = CustTable::find(combination.DisplayValue);    
        }
        else
        {
            if (ledgerJournalTrans.AccountType == LedgerJournalACType::Cust)    
            {
                vendTable = VendTable::find(combination.DisplayValue);    
            }                
        }
    }

}



Second Option:
For dummies :)

ledgerJournalTrans has a method accountDisplay()

static void accountEasyWay(Args _args)
{
    LedgerJournalTrans                      ledgerJournalTrans;
    CustTable                               custTable;
    VendTable                               vendTable;
    
    //I assume that we already have a record 
    //from ledgerJournalTrans

    if (ledgerJournalTrans.AccountType == LedgerJournalACType::Cust)    
    {
        custTable = CustTable::find(ledgerJournalTrans.accountDisplay());    
    }
    else
    {
        if (ledgerJournalTrans.AccountType == LedgerJournalACType::Cust)    
        {
            vendTable = VendTable::find(ledgerJournalTrans.accountDisplay());    
        }                
    }

}

No comments:

Post a Comment