web
You’re offline. This is a read only version of the page.
close
Skip to main content
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 30

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,106 on at
    RE: qbds query in ax 2012 r3

    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
    30 on at
    RE: qbds query in ax 2012 r3

    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
    30 on at
    RE: qbds query in ax 2012 r3

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

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

    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,106 on at
    RE: qbds query in ax 2012 r3

    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
    30 on at
    RE: qbds query in ax 2012 r3

    Uday,

    testing purpose i have added the below line

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

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

    i removed , but still it's coming

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

    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
    30 on at
    RE: qbds query in ax 2012 r3

    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,106 on at
    RE: qbds query in ax 2012 r3

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,004

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 857 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 548 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans