Stack trace error when lookup vendor default accounts in ledger journal

Code
// MODIFICATION to Classes/DimensionAutoCompleteVendDefaultFilter:
public void filterQuery(Query queryLoadAutoCompleteDataEventArgs _eRecId _dimensionAttributeIdDimensionStorage _currentValues)
{
    
QueryBuildDataSource qbds;

    
Common common;
    
LedgerJournalACType accountType;
    
RecId ledgerDimensionId;
    
VendTable vendTable;

    
common dataSource.cursor();

    if (
typeof(common) != typeof(null)
        && 
_dimensionAttributeId == DimensionAttribute::getMainAccountDimensionAttribute()
        && 
_e.autoCompleteDataMode() == AutoCompleteDataMode::ValidValues)
    {
        
accountType common.getFieldValue(accountTypeFieldName);
        
ledgerDimensionId common.getFieldValue(accountFieldName);
        
vendTable VendTable::findByLedgerDimension(ledgerDimensionId);

        if (
vendTable.AccountNum && VendDefaultAccounts::existDefaultForType(vendTable.AccountNumLedgerJournalACType::Ledger))
        {
            
qbds query.dataSourceTable(tableNum(DimAttributeMainAccount));

            if(
qbds// <-- MODIFICATION
            
{
                
qbds qbds.addDataSource(tableNum(DimensionAttributeValueCombination));
                
qbds.joinMode(JoinMode::ExistsJoin);
                
qbds.addLink(fieldNum(DimAttributeMainAccountRecId), fieldNum(DimensionAttributeValueCombinationMainAccount));

                
qbds qbds.addDataSource(tableNum(VendDefaultAccounts));
                
qbds.addLink(fieldNum(DimensionAttributeValueCombinationRecId), fieldNum(VendDefaultAccountsLedgerDimension));

                
qbds.addRange(fieldNum(VendDefaultAccountsLedgerJournalACType)).value(QueryValue(LedgerJournalACType::Ledger));

                if(
VendDefaultAccounts::existVendAccountForType(vendTable.AccountNumLedgerJournalACType::Ledger))
                {
                    
qbds.addRange(fieldNum(VendDefaultAccountsVendAccount)).value(queryValue(vendTable.AccountNum));
                }
                else if(
VendDefaultAccounts::existVendGroupForType(vendTable.VendGroupLedgerJournalACType::Ledger))
                {
                    
qbds.addRange(fieldNum(VendDefaultAccountsVendGroup)).value(queryValue(vendTable.VendGroup));
                }
            }
            
// MODIFICATION -->
            
else
            {
                
qbds query.dataSourceTable(tablenum(DimAttrTranslMainAccount));

                if(
qbds)
                {
                    
qbds qbds.addDataSource(tableNum(DimensionAttributeValueCombination));
                    
qbds.joinMode(JoinMode::ExistsJoin);
                    
qbds.addLink(fieldNum(DimAttrTranslMainAccountRecId), fieldNum(DimensionAttributeValueCombinationMainAccount));

                    
qbds qbds.addDataSource(tableNum(VendDefaultAccounts));
                    
qbds.addLink(fieldNum(DimensionAttributeValueCombinationRecId), fieldNum(VendDefaultAccountsLedgerDimension));

                    
qbds.addRange(fieldNum(VendDefaultAccountsLedgerJournalACType)).value(QueryValue(LedgerJournalACType::Ledger));

                    if(
VendDefaultAccounts::existVendAccountForType(vendTable.AccountNumLedgerJournalACType::Ledger))
                    {
                        
qbds.addRange(fieldNum(VendDefaultAccountsVendAccount)).value(queryValue(vendTable.AccountNum));
                    }
                    else if(
VendDefaultAccounts::existVendGroupForType(vendTable.VendGroupLedgerJournalACType::Ledger))
                    {
                        
qbds.addRange(fieldNum(VendDefaultAccountsVendGroup)).value(queryValue(vendTable.VendGroup));
                    }
                }
            }
            
// MODIFICATION <--
        
}
    }
}
AX versionMicrosoft Dynamics AX 2012
PropertiesCreated by Alex 2014-12-03 13:30:34 (Public)