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

Announcements

News and Announcements icon
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
    239,874 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
    239,874 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 10

#2
Harisgillani Profile Picture

Harisgillani 4

#2
dserp Profile Picture

dserp 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans