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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to correctly display the sum of the fields of selected rows in the form grid?

(0) ShareShare
ReportReport
Posted on by 845

Hello,

I have a requirement to display the total quantity sum of selected rows on my custom form. I used MultiSelectionHelper and it works for me, but not quite as required. It only works if I select the rows with using the SHIFT button.... If I select individual rows by selecting the blue checkmark (blue circle), the values do not sum up....

  public void markChanged()
        {
            MultiSelectionHelper helper = MultiSelectionHelper::construct();
            helper.parmDatasource(InventTrans_ds);
            InventTrans InventTransTmp;

            Qty qtySum;
            super();
            
            InventTransTmp = helper.getFirst();
            
            if (InventTransTmp.RecId)
            {
                while (InventTransTmp.RecId)
                {
                    qtySum -= InventTransTmp.Qty;
                    InventTransTmp = helper.getNext();
                }
            }
            plannedqty.realValue(qtySum);
        }

helper.png

Can anyone suggest something?
Thanks.

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    InventTransTmp = InventTrans_ds.getFirst(1)? 
    InventTrans_ds.getFirst(1):InventTrans_ds.cusrsor();
    
    while (InventTransTmp)
    {
    info (InventTransTmp.fieldname);
    InventTransTmp= InventTrans_ds.getNext();
    }

    Try this instead of multiselect class.

  • Shooowtek Profile Picture
    845 on at

    Hello Bharani Preetham Peraka,

    Unfortunately, it doesn't work.

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Can you send the error or code? It is working I have tested it now.

  • Shooowtek Profile Picture
    845 on at

    I don't getting any error. It just doesn't sum up the quantity when I select the rows one by one, by selecting the blue marker (blue circle). It works as before, i.e. when I use SHIFT to select several rows....

    public void markChanged()
            {
    
                InventTrans InventTransTmp;
                Qty qtySum;
                super();
                
                InventTransTmp = InventTrans_ds.getFirst(1) ? InventTrans_ds.getFirst(1):InventTrans_ds.cursor();
    
                while (InventTransTmp)
                {
                    qtySum -= InventTransTmp.Qty;
                    InventTransTmp = InventTrans_ds.getNext();
                }
                plannedqty.realValue(qtySum);
            }

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Have you debugged it? You are saying sum, but your code seems to be subtraction. The code will work like if you select multiple lines at a time like on clicking all rows select in form or by clicking ctrl and selecting a row. If it is not working means you need to debug it or give a info log for every loop. Then check what is mistake in you code.

  • Shooowtek Profile Picture
    845 on at

    Yes, in this case there is subtraction, because I only have negative values in the table.

    I did some debugging and found that selecting a row by clicking on the blue marker does not trigger the markChanged method. Selecting a row by clicking directly on the row triggers this method.

    141348.png

    Now the question if is a standard operation, or does my form have a bug? Because it is a bit strange....

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    So if this issue is resolved you can close the question and mark the answer which ever is worked and for your other question please open a new thread.

  • Shooowtek Profile Picture
    845 on at

    It was not completely resolved, because the question was left whether it is the correct operation that this method does not run when selecting a line through the blue marker/circle....

    I thought it does not matter which way the row is selected

  • Suggested answer
    Mohit Rampal Profile Picture
    12,573 Moderator on at

    Hi, Check this article

    erpdax.wordpress.com/.../

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Can you let us know which form is that you are working? We cannot confirm if it is a bug from MS side or your custom code until unless we check the same.

    Also as you said, it should not matter even if you directly select different records by giving ctrl or by clicking that blue Mark.

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 Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 347 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 197

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans