Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

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

*This post is locked for comments

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 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 230,198 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans