web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

qbds query in ax 2012 r3

(0) ShareShare
ReportReport
Posted on by 56

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!

I have the same question (0)
  • udaY-ch Profile Picture
    5,175 on at

    hi,

    What is it you are trying to achieve. Can you explain your requirement clearly.

    The code you given here is not complete it seems. 

    Uday

  • @rp@n Profile Picture
    56 on at

    i have already mentioned my requirement

    see i the above dialog i mentioned customer account and customer group rite?

    those customer account and cust group i wants to get in my above query. how i will acheive this?

    this is my question

    hope you understnd

  • @rp@n Profile Picture
    56 on at

    yes, the above is not completed, thats why i am asking....

  • @rp@n Profile Picture
    56 on at

    hi all,

    6170.s5.jpg

    the right hand side select is coming form Query -- CustCustGroupQR

    5165.Q.jpg

    I write below code

    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();
    qbds = query.addDataSource(tablenum(CustConfirmJour));

    // 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));

    }

    }

    As per the above date range , the below is the report output

    cusr1.jpg

    NOTE -- I gave in select parameter Customer = A00001, So, the report should be BLANK but it's fetching the data

    The actual customer is "M-0001"

    Kindly let me know why parameter is not filtering the data? what code i need to modify?

    please give me more shed on this.

    thanks!

  • udaY-ch Profile Picture
    5,175 on at

    Hi

    You should remove this range,

    qbds.addRange( fieldNum(CustConfirmJour, SalesId)).value("440-000009");

    qbr = qbds.addRange(fieldNum(CustConfirmJour, SalesId));

    qbr.value("");

    Uday.

  • @rp@n Profile Picture
    56 on at

    Uday,

    testing purpose i have added the below line

    qbds.addRange( fieldNum(CustConfirmJour, SalesId)).value("440-000009");

  • @rp@n Profile Picture
    56 on at

    i removed , but still it's coming

  • udaY-ch Profile Picture
    5,175 on at

    hi

    ok, In your query you have added data source (query.adddatasource) but haven't added relation,

    qbds.relations(true); should be added.

    Uday

  • @rp@n Profile Picture
    56 on at

    still is coming...

    my updated code --

    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();

       qbds = query.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-ch Profile Picture
    5,175 on at

    Hi,

    Try this

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

    qbds.relations(true);

    Uday

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 608

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 591 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans