Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to clear selection field of sum in a query in x++

(0) ShareShare
ReportReport
Posted on by

Hi all,

I have applied a group by and sum of in a form, modifying its data source execute query method.

maYearlySummaryDatasource.addGroupByField(fieldNum(maYearlyAffiliateTable,groupId));
maYearlySummaryDatasource.addSelectionField(fieldNum(maYearlyAffiliateTable,AmountCur),SelectionField::Sum);

based on a checkbox selection this group by and sum should be applied. I have written logic for that.

I want to clear the group by and sum of on unticking the check box.

I was able to clear the group by with 

this.query().clearGroupBy();

but unable to clear the (sum of) with 

this.query().clearHavingFilters(maYearlySummaryDatasource,fieldStr(maYearlyAffiliateTable,AmountCur));

Kindly suggest how to achieve this.

Thanks,

Praveen.

 

How to clear selection field with sum in a query in x++

*This post is locked for comments

  • Martin Dráb Profile Picture
    234,035 Most Valuable Professional on at
    RE: How to clear selection field of sum in a query in x++

    Yes, clearFieldList() clears the whole field list, i.e. all fields.

  • Community Member Profile Picture
    on at
    RE: How to clear selection field of sum in a query in x++

    Hi martin,

    The datasource().fields().clearFieldList(). is clearing all the fields except recid.

    the output shows un retrieved for all the fields.

    I have added the following lines in the code and I'm getting the proper output as expected.

           this.query().clearGroupBy();

           maYearlySummaryDatasource.fields().clearFieldList();

           maYearlySummaryDatasource.addAllFields(tableStr(maYearlyAffiliateTable));

    Here the this.query().clearGroupBy(); is neeeded becasue if removed its giving an sql error as 

     SELECT T1.GROUPID,T1.GROUPID FROM MAYEARLYAFFILIATETABLE T1 WHERE ((PARTITION=?) AND (DATAAREAID=?)) GROUP BY T1.GROUPID,T1.GROUPID ORDER BY T1.GROUPID,T1.GROUPID OPTION(FAST 20)

    A column has been specified more than once in the order by list. Columns in the order by list must be unique.


    Its selecting groupid twice.

    The requirement is completed now with your suggestion.

    Appreciate your help.

    Thank you,

    Praveen.

     

  • Verified answer
    Martin Dráb Profile Picture
    234,035 Most Valuable Professional on at
    RE: How to clear selection field of sum in a query in x++

    Try fields().clearFieldList().

    HAVING is something else.

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics

Product updates

Dynamics 365 release plans