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 :
Finance | Project Operations, Human Resources, ...
Answered

Recid Count in real time when using modified method

(1) ShareShare
ReportReport
Posted on by 229
Hi i need to count recId in real time in a modified method,

Is it possible or not ?

Because, i m counting element checked in a grid but when i m using modified method to perform some process and using count in there i didnt have the real count, if i unchecked a row i always have a difference of 1 in my count.

How to reach my goal please ?

Thanks.
I have the same question (0)
  • Waed Ayyad Profile Picture
    9,214 Super User 2026 Season 2 on at
    Hi,
     
    What do you mean by in real time?
     
     
    Thanks,
    Waed Ayyad
  • Martin Dráb Profile Picture
    240,357 Most Valuable Professional on at
    You'll need to give us more information. We don't know what you mean by "not the real count", what you're counting at all and so on.
  • Awaxx Profile Picture
    229 on at
    i'm counting the number of element which are checked in my grid on total of element of my grid to calculate percent of element checked in my grid and update a field to display the value

    so when i modify my grid by checking or unchecking and element i want the value displayed to be refreshed with the real count
  • Martin Dráb Profile Picture
    240,357 Most Valuable Professional on at
    Let me try to help to describe your situation.
     
    You mentioned some database queries, therefore it seems that you store the information about "checked" records in database. If so, is it a field in the table with "elements" or in a separate table? If in a separate table, is it a persistent table or a temporary one? If you store it in a normal table, it means that the information about checked records is the same for all users. Please confirm these things.
     
    Then please explain what problem you have with counting. How are you doing it and what result is your code giving instead of what you intended?
  • Martin Dráb Profile Picture
    240,357 Most Valuable Professional on at
    We already discussed this in a duplicate thread, but it disappeared. Maybe someone deleted the wrong one by mistake. [Update: for some reason, no replies were shown to me for some time.]
     
    Let me quickly repeat what I said there. The description isn't good enough; we can't help you until you do a better job in explaining your implementation and your problem. Let me try to help you with that.
     
    It seems that you store information about checked records in database. Is it correct? If so, where you store it? In the table of "elements", or in a separate table? If a separate one, is it a persistent table or temporary? If you use a persistent table, it means the checking of records is shared by all users.
     
    Regarding the calculation, didn't you forget that the current record hasn't been saved yet if you run your calculation in modified()? I think you should calculate it after saving the record. If you agree with me, you've used a wrong method. modified() is run before saving; do it in write() (below super()) instead.

    If you insist on calculating the value before saving, you must add or subtract the current record from the number you get from database.
  • Awaxx Profile Picture
    229 on at
    here's the code of my modified method :
     
            public boolean modified()
            {
                boolean ret;
    
                EUKChinaOrders chinaOrders = EUKChinaOrders_ds.cursor();        
                
                ret = super();
    
                // Complete update order when checked and calculate score
                EUKChinaOrdersHelper.completeOders(chinaOrders);
                
                EUKChinaOrdersHelper.calculatePartOfCheckedOrders(chinaOrders.ordersId);
    
                return ret;
            }
     
     
    and there how i calculate :
     
     
    Public void calculatePartOfCheckedOrdersOrdersId _ordersId)
        {
            EUKchinaOrders      totalOrders, ordersChecked, updateOrders;
            EUKScore            score;
    
            int totalOrdersCount;
            int ordersCheckedCount;
    
            select count(RecId) from totalOrders
                    where totalOrders.ordersId== _ordersId;
    
            totalOrdersCount = totalOrders.RecId;
    
            select count(RecId) from ordersChecked
                    where ordersChecked.ordersId== _ordersId
                    && ordersChecked.checked == true;
    
            ordersCheckedCount = ordersChecked.RecId;
    
            score = round((ordersCheckedCount /totalOrders) * 100, 0.1);
    
            select forupdate updateOrders
                   where updateOrders == _ordersId
            if(updateOrders)
              {
                updateOrders.score = score;
                updateOrders.update();
              }
        }
    




     
  • Verified answer
    Martin Dráb Profile Picture
    240,357 Most Valuable Professional on at
    Please respond to this part of my previous reply:
     
    Regarding the calculation, didn't you forget that the current record hasn't been saved yet if you run your calculation in modified()? I think
    you should calculate it after saving the record. If you agree with me, you've used a wrong method. modified() is run before saving; do it in
    write() (below super()) instead.
     
    Also, updating the table in calcCompletedScoreCoverage() is a bug. It assumes that the record was saved, but modified() gets calls before the record was saved and it may never be (because a validation fails, there is a network error or so). This may cause data inconsistencies.

    And try to compile your code; you'll see that it doesn't even compile. When you make it compilable and runnable, you may spot another bug: you're updating a random record in EUKchinaOrders. According to the other code, there may be more than one record with the same ordersId while you're updating just one of them (without choosing which one). It might mean that even the data model is wrong.
     
  • Awaxx Profile Picture
    229 on at
    Ok i get it. I have migrate the calculation after the modification is done on the write() method now i have the real. I fixed the other points too it was juste a mistake when i paste my code it was missing a part for having the good id.

    thank you martin

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 July Top 10 Community Leaders

These are the community rock stars!

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

#1
SajeedMullaji Profile Picture

SajeedMullaji 366

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 260 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans