Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

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

Posted on by Microsoft Employee

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++

  • Martin Dráb Profile Picture
    Martin Dráb 228,089 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
    Community Member Microsoft Employee 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
    Martin Dráb 228,089 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.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,252 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,089 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans