Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

The highest version Number

(1) ShareShare
ReportReport
Posted on by 8
Hi All,
 
I am trying to calculate the sum of the line Amount from the Purchase line archives table but, I need just the highest /version No./ foreach line and with the same /Job No./,
I tried this but it's not working.
Can anyone Help please?
Thank you.
  • SM-29041600-0 Profile Picture
    8 on at
    The highest version Number
    Hi All,
    Thank you very much for your response!
    I tried to work with the query, it brings the last version, but I need to sum the line_amount for the records with the same "Job No."

    This is my query:
    query 50100 "Purchase Line Archive ZWT"
    {
        QueryType = Normal;
        OrderBy =descending(Version_No_);
        elements
        {
            dataitem(Purchase_Header_Archive; "Purchase Header Archive")
            {
                column(No_; "No.")
                {
                }
                column(Document_Type; "Document Type")
                {
                }
     
                dataitem(Purchase_Line_Archive; "Purchase Line Archive")
                {
                    DataItemLink = "Document No." = Purchase_Header_Archive."No.", "Document Type" = Purchase_Header_Archive."Document Type";
                    SqlJoinType = InnerJoin;
                    column(Document_No_; "Document No.")
                    {
                    }
                    column(Line_No_; "Line No.")
                    {
                    }
                    column(Job_No_; "Job No.")
                    {
                       
                    }
                    column(Version_No_; "Version No.")
                    {
                        Method = Max;
                    }
                    column(Line_Amount; "Line Amount")
                    {
                    }
                }
            }
        }
     
        trigger OnBeforeOpen()
        begin
     
        end;
    }
  • Suggested answer
    YUN ZHU Profile Picture
    79,097 Super User 2025 Season 1 on at
    The highest version Number
  • Yael Suarez Profile Picture
    117 on at
    The highest version Number
    Hello, how have you tried to try with

    VariableRecord.SetCurrentKey(Version No);
    VariableRecord.SetAscending(Version No, true);

    substituting the version setrange into your line of code
    I hope this can help you

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,245 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,925 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans