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)

Show Total at the bottom of Grid from a Display Method column?

(0) ShareShare
ReportReport
Posted on by 1,813

Hii,

I want to show the total or sum of all lines in a grid, but the column is a display method.

I followed this article of Martin Dráb and successfuly showed total of CustInvoiceJour InvoiceAmountMST field in the grid bottom.
http://dev.goshoom.net/en/2015/11/summarized-values-in-ax-form/

But don't understand how to do it with a display method?

Here is the detail..

Form Data source
0257.datasource.png

This is my form. Here Balance column is CustTrans remainAmountMST() display method. I want to show total of Balance column at the bottom of grid.

4150.form.png

Thanks,

*This post is locked for comments

I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    Would not adding the keyword Display in the signature of your  methods, would help to get the needed results...?

  • Rana Anees Profile Picture
    1,813 on at

    Hii Shoaib,

    I tried but and getting error..

    qbds.addSelectionField(fieldNum(CustTrans, remainAmountMST), SelectionField::Sum);

    or

    qbds.addSelectionField(fieldNum(CustTrans, remainAmountMST()), SelectionField::Sum);

    Error: The table CustTrans does not contain the field remainAmountMST.

  • Rana Anees Profile Picture
    1,813 on at

    I did't get your point

    "Would not adding the keyword Display in the signature of your  methods, would help to get the needed results...?" ..?

    Where to add...code example please.

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    I am referring to the blog-post of Martin that you have presented in your original thread. Which means if you copy paste same method and add the keyword display in top line.

    about your error, system is saying that CustTrans Table is not having a field named as remainAmountMST. Have you checked if the field exists in CustTrans

  • Rana Anees Profile Picture
    1,813 on at

    remainAmountMST is a display method in CustTrans table. Even adding display signature in not the solution.

    In Martin example code, he is using a direct field in a table, but I need to use a display method instead of a field.

    Is there some other solution....?

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    Well, you cannot use display methods with addSelectionField

    You need to adopt some other approach such as x++ method that can return you sum of remaining amount all invoices.

    The basic underlying mathematics is as under

    Remaining Amount = AmountMST + ExchAdjustment - SettleAmountMST;

  • Rana Anees Profile Picture
    1,813 on at

    Hii,

    As Shoaib suggested, I am getting sum of all CustTrans rows.  Its showing all Total Balance and showing in control TotalARBalance at grid bottom.

    But when I filter in the grid, its not updating....showing the same amount on grid filtration as well.

    Please suggest any better way to get it done..

    public void updateTotalARBalance()
    {
        real TotalBalance;
    
        CustTrans summedCustTrans;
    
        select sum(AmountMST), sum(ExchAdjustment), sum(SettleAmountMST) from summedCustTrans
            where summedCustTrans.DataAreaId == curext();
    
        TotalBalance = (summedCustTrans.AmountMST + summedCustTrans.ExchAdjustment - summedCustTrans.SettleAmountMST);
    
        TotalARBalance.realValue(TotalBalance);
    }

    Thanks,

  • Suggested answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Your method uses a hard-coded query, completely independent on the query of the form. Therefore it a user filter the form, it has no impact on your method; it'll always return the same thing.

    If you go back to the block post, you'll see how the query is copied from the form and the copy is aggregated. This is what you must do too, instead of using your hard-coded select statement. The only difference is that you'll add SUM aggregations for all three fields and you'll calculate the balance before setting the value of TotalARBalance.

  • Rana Anees Profile Picture
    1,813 on at

    Hii Martin Dráb,

    I was really waiting for your reply and am happy you are here.

    I got your point and trying to do like this and having errors....

    qbds.addSelectionField(fieldNum(CustTrans, AmountMST+ExchAdjustment, SettleAmountMST), SelectionField::Sum);

    If you please elaborate the correct syntax...will make my day.

    Thanks again.

  • Verified answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Your syntax is completely wrong. You're trying to get a field number of AmountMST+ExchAdjustment, SettleAmountMST, which clearly isn't a valid field name.

    Also, you already know how to write the select statement, therefore follow the same approach. You don't have a single SUM function for the aggregation; you have three SUM functions, each for a single field. Therefore call addSelectionField() three times, once for every field you want to sum:

    qbds.addSelectionField(fieldNum(CustTrans, AmountMST), SelectionField::Sum);
    qbds.addSelectionField(fieldNum(CustTrans, ExchAdjustment), SelectionField::Sum);
    qbds.addSelectionField(fieldNum(CustTrans, SettleAmountMST), SelectionField::Sum);

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans