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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Queries showing different results

(0) ShareShare
ReportReport
Posted on by

4300.forum.PNG

I have created a 2 same queries using AOT and through x++ but I am getting different results for the queries

This is my X++ query

static void Check2(Args _args)
{
QueryRun queryRun;
CustInvoiceJour custInvoiceJour;

Query q;
QueryBuildDataSource qbd;
QueryBuildRange qbr;


q = new Query();
qbd = q.addDataSource(TableNum(CustInvoiceJour));
qbr = qbd.addRange(FieldNum(CustInvoiceJour, InvoiceAccount));
qbd.firstOnly(true);
qbr.value('100002');
info(q.toString());
queryRun = new QueryRun(q);
while (queryRun.next())
{
custInvoiceJour = queryRun.get(tableNum(CustInvoiceJour));
info(strFmt("%1",custInvoiceJour.InvoiceAmount));
}
pause;
}

This is my AOT query

Aot-query.PNG

static void check(Args _args)
{
QueryRun queryRun;

CustInvoiceJour custInvoiceJour;
;
Query query;
QueryBuildDataSource qbd;
query = new Query(queryStr(PreInvoiceAmount));
query.dataSourceTable(tableNum(custInvoiceJour))
.addRange(FieldNum(CustInvoiceJour,InvoiceAccount)).value('100002');
info(query.toString());
queryRun = new QueryRun(queryStr(PreInvoiceAmount));

while (queryRun.next())
{
custInvoiceJour = queryRun.get(tableNum(CustInvoiceJour));
info(strFmt("%1",custInvoiceJour.InvoiceAmount));
}
pause;
}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Rustem Galiamov Profile Picture
    8,072 on at

    Hi AX@beginner!

    It's because of this string in check() job:

    queryRun = new QueryRun(queryStr(PreInvoiceAmount));

    It should be:

    queryRun = new QueryRun(query);

  • Community Member Profile Picture
    on at

    Hi Rustem

    Thank you for the solution

    Now 

    I have assign this query to a Infopart and I am adding the range for the query in the salestable form

    but the value is coming without taking the range

    8228.forum2.PNG

    I have written the below lines of code in SalesTable initmethod() but the query is executing without  range

    //preInvoiceAmount
    query = new Query(queryStr(PreInvoiceAmount));
    query.dataSourceTable(tableNum(custInvoiceJour))
    .addRange(FieldNum(CustInvoiceJour,InvoiceAccount)).value('100002');
    info(query.toString());
    queryRun = new QueryRun(query);

    I was suppose to get the below value after adding the range

    I was8228.forum2.PNG

    Can you please help me ?

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    It's not possible to say without seeing all your code, but it seems that the query that you create in "initmethod" (do you mean "init" method?) has nothing to do with the query of the infopart. Basically you are creating a new query but how would the infopart know that you want it to use it?

    You have to find where the infopart query is initialized and write your code there so that you add your range to the actual infopart query.

    So you should not create a new query, instead add your range to the existing query.

  • Community Member Profile Picture
    on at

    forum3.PNG

    This is the infopart i created and I had assign the query with my query

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Yes but you are not assigning your range to the query object that the infopart is using.

    You are creating a new query object in your code (based on the same AOT query) and adding your range to it. But your info part is not using that query object. At least it looks like that based on the incomplete code that you are sharing.

  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

    Hi!

    Sales order has already information which you try to add about lastInvoiceAmount. It's CustStatisticsRecentActivity form part

    Screen-Shot-2018_2D00_09_2D00_20-at-10.57.43.png

    But if you want to add your own form part with related information, take a look at CustStatisticsRecentActivity form part and try to do the same thing. 

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans