Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Recid Count in real time when using modified method

(1) ShareShare
ReportReport
Posted on by 203
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.
  • Awaxx Profile Picture
    Awaxx 203 on at
    Recid Count in real time when using modified method
    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
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional on at
    Recid Count in real time when using modified method
    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
    Awaxx 203 on at
    Recid Count in real time when using modified method
    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();
              }
        }
    




     
  • Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional on at
    Recid Count in real time when using modified method
    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.
  • Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional on at
    Recid Count in real time when using modified method
    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?
  • Awaxx Profile Picture
    Awaxx 203 on at
    Recid Count in real time when using modified method
    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
    Martin Dráb 230,371 Most Valuable Professional on at
    Recid Count in real time when using modified method
    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.
  • Waed Ayyad Profile Picture
    Waed Ayyad 6,493 Super User 2024 Season 2 on at
    Recid Count in real time when using modified method
    Hi,
     
    What do you mean by in real time?
     
     
    Thanks,
    Waed Ayyad

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans