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)

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

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    Try fields().clearFieldList().

    HAVING is something else.

  • Community Member Profile Picture
    on at

    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.

     

  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

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

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans