Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

Sum of quantity field without declaring it a flow field.

Posted on by Microsoft Employee

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Sum of quantity field without declaring it a flow field.

    Directly use the decQty variable in the SourceExpr property.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Sum of quantity field without declaring it a flow field.

    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!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Sum of quantity field without declaring it a flow field.

    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!

  • Suggested answer
    RockwithNav Profile Picture
    RockwithNav 6,562 on at
    RE: Sum of quantity field without declaring it a flow field.

    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.

  • Verified answer
    TharangaC Profile Picture
    TharangaC 23,116 on at
    RE: Sum of quantity field without declaring it a flow field.

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

  • mmv Profile Picture
    mmv 11,465 on at
    RE: Sum of quantity field without declaring it a flow field.

    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
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Sum of quantity field without declaring it a flow field.

    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.

  • Verified answer
    RE: Sum of quantity field without declaring it a flow field.

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans