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 :
Microsoft Dynamics AX (Archived)

How to create query for x++ code

(0) ShareShare
ReportReport
Posted on by 435

Hi All,

Please find the attached screenshot.How to create the AOT query for this.Comm.JPG

Parent Data source is AngryDetails it have Amount field with programRef like

ProgramRef  Amount RefRecId

0001                0.45       56324

0001                0.50       56324

Child Data source is HalfInvoice it have custInvoiceId.

custInvoiceId RecId

CIV-000654   56324

My input is CustInvoiceId

I will need output like in Grid

ProgramRef amount

0001           0.95

Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    István Orosz Profile Picture
    2,137 on at
    RE: How to create query for x++ code

    Hi,

    You can refer to e.g. this article please.

    Regards,

    István

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: How to create query for x++ code

    You could create a query/view with a grouping on ProgramRef and a sum aggregate function for Amount.

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at
    RE: How to create query for x++ code

    Hi,

    Please construct the query as shown below.

    SumQuery.jpg

    To iterate through the AOT query, you can use the following job/code.

    tatic void sumQuery(Args _args)
    {
        Query query = new query(queryStr(AngryDetailsQuery));
        QueryBuildDataSource qbds;
        queryrun queryrun;
        QuerybuildRange qbr;
        AngryDetails AngryDetails;
        qbds = query.dataSourceTable(tableNum(HalfInvoice));
        qbr = SysQuery::findOrCreateRange(qbds, fieldNum(HalfInvoice, CustInvoiceId));
        qbr.value(queryValue("CIV-000654"));
    
        queryrun = new queryrun(query);
    
        while (queryrun.next())
        {
            AngryDetails = queryrun.get(tableNum(AngryDetails));
            info(strFmt("%1 %2", AngryDetails.ProgramRef, AngryDetails.AccruedAmount));
        }
    }
  • Suggested answer
    István Orosz Profile Picture
    2,137 on at
    RE: How to create query for x++ code

    Hi,

    You can build up an AOT query similar to this:

    Query_5F00_sample_5F00_1.jpg

    Than you can iterate through the query by code.

    Regards,

    István

  • AX 2012 r3 Profile Picture
    2,426 on at
    RE: How to create query for x++ code

    Hi,

    Follow the Steps.

    1.Create Query add First Datasource as AngryDetails

    Dynamic fields - yes  or no based on your requirement 

    2.Drag ProgramRef  field from Datasource and Place into Group Section in Query

    3.Add child datasource HalfInvoice  to AngryDetails

    Give Relation Property on HalfInvoice  - Yes (if table relation is there)

    (If table level relation is not there create relation under HalfInvoice  in Query)

    4.Create a view

    5.add this Query to View Datasource

    6.Right click on View Fields and Create New Field - ProgramRef  

    7.Right click on View Fields and Create New Field - Give Datasource,FieldName,Aggregation -Sum

    8.Create form 

    9.Add View as Datasource to form

    10.Create Grid and give Datasource

    11.Drag fields from Form Datasource.

    Thats it.

    Open Form and See.

    Note :- You cannot use Query field aggregate.When you add Query directly to form you wont get aggregate field as per i know

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans