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 NAV (Archived)

Sum of quantity field without declaring it a flow field.

(0) ShareShare
ReportReport
Posted on by

Sir,

        I've created a field named 'Quantity Available' in MR Subform page which will sum up all the quantityes available in the 'Quantity' field of the Item Ledger Entry table.I didn't declare the field as a flowfield.  I wrote the following code in MR Subform page:

Quantity Available - OnValidate()

RecILE.SETCURRENTKEY(RecILE."Location Code");

RecILE.CALCSUMS(RecILE.Quantity);

But still doesn't get the required result. What should I do?

                                             Thank You,

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Nareshwar Raju Vaneshwar Profile Picture
    5,596 on at

    Hi Rajat,

    You are using the wrong trigger I guess. OnValidate() trigger works when there is a change in the field.

    But the code looks fine, so if you are using this code on a Page, use OnAfterGetRecord() or OnOpenPage() trigger.

    Hope it helps.

  • Verified answer
    Community Member Profile Picture
    on at

    Use following code.

    ILE.Setcurrentkey("Item No.","Location Code");

    ILE.Setrange("Item No.","Item No.");

    ILE.Setrange("Location Code","Location Code");

    IF ILE.FINDFIRST THEN BEGIN

     ILE.Calcsums(Quantity);

     decQty :=  ILE.Quantity;

    END;

    You can use the decQty variable to display the required results.

  • mmv Profile Picture
    11,471 on at

    Hi Vishal,

    In order to use the CALCSUMS, you don't need to find the Record.  You may simply write the CALCSUMS just after your SETRANGE.

  • Verified answer
    Tharanga Chandrasekara Profile Picture
    23,118 on at

    Your code looks totally ok to me. I even tried the same code and it works like a charm. As nareshwar mention you might need to change the trigger where you have written your code. I would suggest you to go with OnAfterGetRecord( )

  • Suggested answer
    RockwithNav Profile Picture
    8,625 Super User 2025 Season 2 on at

    Hey Rajat,

    I will recommend you to first of all have a strong grip on the sequences of the triggers and which triggered is fired when.

    As everyone in the thread recommended write your code on OnAfterGetRecord() - This trigger gets executed everytime you change the record on page.

    Code what you are writing is OK and too what Vishal recommended but I will prefer Vishals one keeping Performance in mind.

  • Community Member Profile Picture
    on at

    Thank you Vishal for the response. I have one more question to ask you. I have written the code within OnAfterGetRecord() trigger & it works fine.

    But I want the records stored in the decQty variable to be shown in the MR Line table which is the source table of this page. I wrote following code within the same trigger which is:

    Rec."Quantity Available":=decQty;

    But still it doesn't shows the records in the table. Can you plz help me!

  • Community Member Profile Picture
    on at

    Thank You Sir. But I have one more question.

    I have declared a variable 'decQty' which stores all the records of 'Quantity' field after CALCSUMS.

    I want the records stored in the decQty variable to be shown in the MR Line table which is the source table of this page. I wrote following code within the same trigger which is:

    Rec."Quantity Available":=decQty;

    But still it doesn't shows the records in the table. Can you plz help me!

  • Suggested answer
    Community Member Profile Picture
    on at

    Directly use the decQty variable in the SourceExpr property.

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 NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans