This post is machine-translated. The original post in german language can be found here.

Query/QueryRun using a temporary table

If you want to run through the contents of a temporary table with a QueryRun, you have to use the method setRecord() of the QueryRun object.

Simple example

static void Job1(Args _args)
{
    TmpFrmVirtual tmpFrmVirtual;
    InventTable inventTable;
    Query q;
    QueryRun qr;
    QueryBuildDataSource qbds1, qbds2;
    
    TmpFrmVirtual populateTmpFrmVirtual()
    {
        TmpFrmVirtual tmpFrmVirtualLocal;    
        
        tmpFrmVirtualLocal.clear();
        tmpFrmVirtualLocal.ItemId = "A0001";
        tmpFrmVirtualLocal.insert();
        
        tmpFrmVirtualLocal.clear();
        tmpFrmVirtualLocal.ItemId = "A0002";
        tmpFrmVirtualLocal.insert();        
        
        tmpFrmVirtualLocal.clear();
        tmpFrmVirtualLocal.ItemId = "A0003";
        tmpFrmVirtualLocal.insert();          
        
        return tmpFrmVirtualLocal;
    }
    
    q = new Query();
    qbds1 = q.addDataSource(tableNum(TmpFrmVirtual));
    
    qr = new QueryRun(q);
    qr.setRecord(populateTmpFrmVirtual());
    while (qr.next())
    {
        tmpFrmVirtual = qr.get(tableNum(tmpFrmVirtual));    
        
        info(tmpFrmVirtual.ItemId);
    }  
}

Example with a join to a non-temporary table

In such a case, the temporary table must be the first DataSource, otherwise a corresponding error message occurs.

static void Job19(Args _args)
{
    TmpFrmVirtual tmpFrmVirtual;
    InventTable inventTable;
    Query q;
    QueryRun qr;
    QueryBuildDataSource qbds1, qbds2;
    
    TmpFrmVirtual populateTmpFrmVirtual()
    {
        TmpFrmVirtual tmpFrmVirtualLocal;    
        
        tmpFrmVirtualLocal.clear();
        tmpFrmVirtualLocal.ItemId = "A0001";
        tmpFrmVirtualLocal.insert();
        
        tmpFrmVirtualLocal.clear();
        tmpFrmVirtualLocal.ItemId = "A0002";
        tmpFrmVirtualLocal.insert();        
        
        tmpFrmVirtualLocal.clear();
        tmpFrmVirtualLocal.ItemId = "A0003";
        tmpFrmVirtualLocal.insert();          
        
        return tmpFrmVirtualLocal;
    }
    
    q = new Query();
    qbds1 = q.addDataSource(tableNum(TmpFrmVirtual));
    qbds2 = qbds1.addDataSource(tableNum(InventTable));
    qbds2.relations(true);
    qbds2.joinMode(JoinMode::InnerJoin);
    qbds2.fetchMode(QueryFetchMode::One2One);
    
    qr = new QueryRun(q);
    qr.setRecord(populateTmpFrmVirtual());
    while (qr.next())
    {
        tmpFrmVirtual = qr.get(tableNum(tmpFrmVirtual));    
        inventTable = qr.get(tableNum(inventTable));
        
        info(tmpFrmVirtual.ItemId + " " + inventTable.NameAlias);
    }    
}

 

These post applies to following version:
Dynamics AX 2012

 
 

 

 
 
 
Posts of the actual month
November 2024
MoTuWeThFrSaSu
 123
45678910
11121314151617
18192021222324
252627282930 
 
© 2006-2024 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.