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

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Calcsum wont work!

(0) ShareShare
ReportReport
Posted on by

Hello, I am in a bit of a problem and I have spent few hours trying to figure it out, but I havent been able to get it to work.

Background Information

On a form, I have a subform (which contains the following fields:- Transaction Type (option :- receipt, cheque), Date (date), Description (text), Amount (decimal)). Also on the form, there is a field called 'Annual Allocation'. All, I had to do is look at all the Transaction type which are off type "Cheque" and add all of there 'Amount' fields. Once you have the totalsum of the Amounts field, compare it with 'Annual Allocation' field. If 'amount' is greater than 'annual allocation'. Throw an error.

Code:

IF Rec."Transaction Type" = Rec."Transaction Type"::Cheque THEN

BEGIN 

lrecJob.GET(Rec."Job No.");

lrecConsumerDisbursement.SETCURRENTKEY("Transaction Type");

lrecConsumerDisbursement.SETRANGE("Job No.", Rec."Job No.");

lrecConsumerDisbursement.SETRANGE("Transaction Type", "Transaction Type"::Cheque);

lrecConsumerDisbursement.CALCSUMS(Amount);

TotalAmount := lrecConsumerDisbursement.Amount+ Rec.Amount;

IF lrecJob."Annual Allocation" < TotalAmount THEN ERROR(NotEnoughFunds);

END;

Some of you guyz might be wondering why I added: rec.Amount to the Total Amount variable. That is because it never use to remember the new value that the user typed. That was just me trying to force it to remmeber the current value (and forget the last one) in the field.

This works most of the time. But Its does not have 100% success rate.

Its not working for the following case:

Lets say I added bunch of records to my subform of transaction type cheque. It will work, untill the Amount field is more than Annual Allocation, at which point it will throw me an error saying: not sufficient funds. At which point user has to change the value in the amount field so the total sum is less than annual allocation. However, even when the user changes the value, it remember the value i had previously (before the error mesage) and the value he/she just changed too, which gives me an even higher total amount, which throws an error all over again. How can i make it forget the value i had previously (before the error message), so it only considers the new value and calculates the totalAmount all over again.

Screenshot to give you a better understanding. http://screencast.com/t/xtrQUutmFpu3

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at
    Re: Calcsum wont work!

    if lrecConsumerDisbursement is a global variable I would add

    lrecConsumerDisbursement.reset

    before

    lrecConsumerDisbursement.SETCURRENTKEY("Transaction Type");

    You could try adding

    lrecConsumerDisbursement.findset

    after

    lrecConsumerDisbursement.SETRANGE("Transaction Type", "Transaction Type"::Cheque);

    I know it's not realy required but I use it all the time anyway... just to be safe

    Denis

  • Community Member Profile Picture
    on at
    Re: Calcsum wont work!

    i tried what you suggested...im still haveing the same issue.

    any other ideas???

  • Community Member Profile Picture
    on at
    Re: Calcsum wont work!

    Did you try creating a FlowField on your Job table

    Sum("Customer Disbusment"."Amount" WHERE (Job No.=FIELD(No.),"Transaction Type=CONST(Cheque))

    Then use the CalcFields function to get the value

    Where did you put your validation code ?

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Alexander Ermakov Profile Picture

Alexander Ermakov 2

#2
SC666 Profile Picture

SC666 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans