Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

qbds query in ax 2012 r3

Posted on by 5,885

hi all,

my requirement is to get the value from dialog and manipulate based on that. like

5265.e1.jpg

***here in the dialog the select parameters is coming from Cust table. i made 1 query and put 2 ranges...

cust account and

cust group.

User can select multiple cust account and cust groups.

i wrote one query but unable to understand how i will call the cust table in my below query? So, that i can get the values , whatever i mentioned in the dialog

My code

class decleration ()

{

QueryRun      queryRun;

}

private void buildQR()
{
Query                                 query;
QueryRun                          qrRun;

QueryBuildDatasource      qbds,qbds1;
QueryBuildRange              qbr;
;

query = queryRun.query();

qbds = query.addDataSource(tablenum(CustConfirmJour));

qBds.addGroupByField(fieldNum(CustConfirmJour,SalesId));

// date range
qbr = qbds.addRange(fieldNum(CustConfirmJour,ConfirmDate));
qbr.value(queryRange(fromDate, toDate));

// group by 
qbds.addGroupByField(fieldNum(CustConfirmJour,SalesId));

// max
qbds.addSelectionField(fieldNum(CustConfirmJour,RecId),SelectionField::Max);

queryRun = new QueryRun(query);

while (queryRun.next())
{
      custConfirmJour = queryRun.get(TableNum(CustConfirmJour));

}

}

new() --

public void new()
{
;
super();
queryRun = new QueryRun(querystr(CustCustGroupQR));
}

run()--

public void run()
{
;
super();
this.excelDataExport();
}

public void excelDataExport()
{
;
.
this.buildQR();

//export data and set permission
}

main() --

static void main(Args _args)
{
GDJ_JPN_SODetailedReport soDetailedReport = new GDJ_JPN_SODetailedReport();
;
if(soDetailedReport.prompt())
{
soDetailedReport.run();
}
}

kindly let me know what i need to add the code for cust table in above query? so, that i can get the values from the dialog in select parameters.

please give me more shed on this.

thanks!

  • @rp@n Profile Picture
    @rp@n 5,885 on at
    RE: qbds query in ax 2012 r3

    thanks Uday

  • Verified answer
    udaY-ch Profile Picture
    udaY-ch 4,616 on at
    RE: qbds query in ax 2012 r3

    Hi,

    When query having multiple datasources we need to specify the datasource to make our new datasource connected to the right parent datasource.

    For that reason, we added datasourceno(1) which is custtable in your case.

    Uday

  • @rp@n Profile Picture
    @rp@n 5,885 on at
    RE: qbds query in ax 2012 r3

    uday,

    what is the difference between these two code ?

    qbds = query.addDataSource(tablenum(CustConfirmJour));

    qbds = query.dataSourceNo(1).addDataSource(tablenum(CustConfirmJour));

    my code is working if customer is not matched ***

    qbds = query.dataSourceNo(1).addDataSource(tablenum(CustConfirmJour));

  • @rp@n Profile Picture
    @rp@n 5,885 on at
    RE: qbds query in ax 2012 r3

    uday,

    give me your contact number please. will talk later

  • udaY-ch Profile Picture
    udaY-ch 4,616 on at
    RE: qbds query in ax 2012 r3

    Hi,

    Great,

    rich.png

    Richtext.png

    Uday

  • @rp@n Profile Picture
    @rp@n 5,885 on at
    RE: qbds query in ax 2012 r3

    it's working bro

    thanks a lot

    how you will paste the code in above format in rich text formatting?

  • Verified answer
    udaY-ch Profile Picture
    udaY-ch 4,616 on at
    RE: qbds query in ax 2012 r3

    Hi,

    You need to assign query as queryRun.query() to get the AOT query.

    query = new Query(queryRun.query());

    qbds = query.dataSourceNo(1).addDataSource(tableNum(CustConfirmJour));

    public void excelExecution()
    {
       Query                   query;
       QueryRun                qrRun;
       TransDate               maxSalesConfrmDate;
       QueryBuildDatasource    qbds,qbds1;
       QueryBuildRange         qbr;
       RecId                   chkRecid;
       boolean                 headerPrint = true;
       i = 1;
    
       // initlize the SysExcelApplication instance
       sysExcelApplication  = SysExcelApplication::construct();
    
       //create excel workbook and excel worksheet
    
       excelWorkbookCollection  = sysExcelApplication.workbooks();
    
       excelWorkbook    = excelWorkbookCollection.add();
    
       excelWorksheetCollection = excelWorkbook.worksheets();
    
       excelWorksheet = excelWorksheetCollection.itemFromNum(1);
       // query ( GDJ_CustCustGroupQR )started ***
       query = new Query(queryRun.query());
    
       qbds = query.dataSourceNo(1).addDataSource(tablenum(CustConfirmJour));
    
       qbds.relations(true);
    
       // date range
    
       qbr = qbds.addRange(fieldNum(CustConfirmJour,ConfirmDate));
    
       qbr.value(queryRange(fromDate, toDate));
    
       qbds.addGroupByField(fieldNum(CustConfirmJour, SalesId));
    
       qbds.addSelectionField(fieldNum(CustConfirmJour, RecId), SelectionField::Max);
    
       /*qbds.addRange( fieldNum(CustConfirmJour, SalesId)).value("440-000009");
    
       qbr = qbds.addRange(fieldNum(CustConfirmJour, SalesId));
    
       qbr.value("");*/
    
       qrRun = new QueryRun(query);
    
       try
       {
           while (qrRun.next())
            {
               custConfirmJour = qrRun.get(TableNum(CustConfirmJour));
            }
    }

    Uday

  • @rp@n Profile Picture
    @rp@n 5,885 on at
    RE: qbds query in ax 2012 r3

    need to add any relation with custtable?

    like addlink...

  • @rp@n Profile Picture
    @rp@n 5,885 on at
    RE: qbds query in ax 2012 r3

    yes,

    public void new()

    {

       ;

       super();

       queryRun = new QueryRun(querystr(GDJ_CustCustGroupQR));

    }

  • udaY-ch Profile Picture
    udaY-ch 4,616 on at
    RE: qbds query in ax 2012 r3

    HI

    Have you added the AOT query to your code ?

    Your code shows query = new Query(); should be new query(querystr(yourQuery));

    Uday

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,513 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,862 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans