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 :
Small and medium business | Business Central, N...
Suggested Answer

adding weight and totals to the sales shipment report

(0) ShareShare
ReportReport
Posted on by 350

hi there,

i added net weight and gross weight to the sales - shipment report via reportextension.

i have to include total weights on the document. total weight should be calculated as a sumproduct of all lines that contain weight info, as:

total = sum of all lines ( quantity * unit weight )

how do i get the correct total weight displayed in the report?

I have the same question (0)
  • Suggested answer
    MahGah Profile Picture
    15,529 on at

    Hi

    For us the answer was to copy standard report and create custom report then in XML include those information and use. But maybe it is a way that you can add calculated weight to standard report.  Like in each line have a hidden field in report that make a calculation for each line then sum it up at the bottom of report.

  • benovic Profile Picture
    350 on at

    thanks for your answer! i want to avoid copying the standard report, since it creates am mess that is not easily maintainable. Currently i am looking into what can maybe done with

    reportextension

    calculated field

    Trigger: OnAfterGetRecord

    but so far no lock. What i find curious, alot of external processes, e.g. shipping companies require the total weight being calculated on every delivery note. Alot of people must have the same problem, but alay i cant seem to find anyone with a similar problem online.

    is everyone just installing addons that solve the problem for them?

  • Suggested answer
    MahGah Profile Picture
    15,529 on at

    Hi

    I am hoping mr yzhums  can provide some help with report.

    Many companies that I know use add-on for shipping (UPS/FedEx/etc). Also, some uses add-on for LTL/FTL. For 3d party some use 3rd party API. 

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    Basically you have two options. You can either create a function that calculates the weight when you run the report or you can add flowfields to the shipment header that sums the weight based on the lines.

    If you only want to show the weight on the report i recommend the function approach.

    The weight is shown in the shipment statistics page.

    pastedimage1648157482756v1.png

    So you can look at how they calculate it there for inspiration. I did not inspect the code, but maybe they have a function there you can reuse.

  • Suggested answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at

    Hi, just a example to add total weight to lines. If you also want lines totals, it is most convenient to add a SUM function in RDLC side.

    pastedimage1648164978729v1.png

    pastedimage1648164988294v2.png

    pastedimage1648165002650v3.png

    Hope this will help.

    Thanks.

    ZHU

  • benovic Profile Picture
    350 on at

    Thanks, ZHU, this is really helpful!

    Edit: nevermind, it worked! i learned a lot!! thank you so much, 

    i have a similar approach, that seems a bit easier, but i don't know if it breaks stuff?

    instead of the modify step i just wrote:

    ///////

    add(Line)

           {

               column(Net_Weight; "Net Weight") { }

               column(Gross_Weight; "Gross Weight") { }

               column(LineNetWeight; "Net Weight" * Quantity) {}

           }

    ///////

    to calculate the totals i changed this to: 

    ///////

    dataset
        {
            add(Header)
            {
                column(Header_TotalNetWeight; TotalNetWeight) { }
            }
            add(Line)

           {

               column(Net_Weight; "Net Weight") { }

               column(Gross_Weight; "Gross Weight") { }

               column(LineNetWeight; AddToNetTotal("Net Weight" * Quantity) { }

           }

    } // end dataset

        local procedure AddToNetTotal(LineWeight: Decimal) LineWeightReturn: Decimal
        begin
            TotalNetWeight += LineWeight;
            LineWeightReturn := LineWeight;
        end;
        var
            TotalNetWeight: Decimal;
    ///////
    my problem is, now,  .... the total value seems to get set initially, before calculating the lines. I know of the SUM() function in RDL, but want to avoid RDL Layouts and keep Word, because we have a design team that hast to go over those files some day.

    I'd like to calc and update the totals in the extension instead of relying on the template file for that.
     I am trying to get the value in the report via MOdify and trigger, but it seems not to work, alas:

    ///////

            modify(Header)
            {
                trigger OnAfterAfterGetRecord()
                begin
                    TotalGrossWeight := TotalGrossWeight;
                end;
            }

    ///////

    i'd be very glad to get this into the header or somewhere else in the report XML. I have  other values i have to integrate as well and would like to have everything in  one place (the extension):
    * Number of packages
    * package dimensions (via Item units of Measure, where i have to also update the weights and "overwrite" the value from the tem card, if it is in there ...)
    is there a way to "fill" the header column after the lines have been calculated?
  • benovic Profile Picture
    350 on at

    For completeness here is my code. I hope i can help others with this.

    reportextension 50999 "Standard Sales - Shipment Ext" extends "Standard Sales - Shipment"
    {
        // in this extension we
        // add weights to the delivery note
        // add package sizes to the delivery note
        dataset
        {
            add(Header)
            {
                column(Header_TotalNetWeight; TotalNetWeight) { }
                column(Header_TotalGrossWeight; TotalGrossWeight) { }
            }
            add(Line)
            {

                column(Net_Weight; "Net Weight") { }
                column(Gross_Weight; "Gross Weight") { }
                column(LineNetWeight; LineNetWeight)
                {
                    DecimalPlaces = 0 : 1;
                }
                column(LineGrossWeight; LineGrossWeight)
                {
                    DecimalPlaces = 0 : 1;
                }
                column(Unit_of_Measure_Code; "Unit of Measure Code") { }
                column(LineUnitSize; LineUnitSize) { }
            }

            modify(Header)
            {
                trigger OnAfterAfterGetRecord()
                begin
                    TotalGrossWeight := TotalGrossWeight;
                    TotalNetWeight := TotalNetWeight;
                end;
            }
            modify(Line)
            {
                trigger OnAfterAfterGetRecord()
                begin

                    //get (width x length x height) as Text
                    LineUnitSize := GetItemUnitSize("No.", "Unit of Measure Code");

                    // if we have a gross weight from th eitem unit of measure,
                    //   use this to calculate the line gross weight and the gross total
                    if ItemUnitOfMeasure.Get("No.", "Unit of Measure Code") then begin
                        if ItemUnitOfMeasure.Weight > 0 then begin
                            "Gross Weight" := ItemUnitOfMeasure.Weight;
                            LineGrossWeight := AddToGrossTotal("Gross Weight" * Quantity);
                        end;
                    end;

                    // use modify to calculate th eline net weight, from the item card
                    LineNetWeight := AddToNetTotal("Net Weight" * Quantity);

                end;
            }



        } //end of Dataset
        requestpage
        {
            //placeholder: later being able to chose including a commercial invoice
        }

        local procedure AddToNetTotal(LineWeight: Decimal) LineWeightReturn: Decimal
        begin
            TotalNetWeight += LineWeight;
            LineWeightReturn := LineWeight;
        end;

        local procedure AddToGrossTotal(LineWeight: Decimal) LineWeightReturn: Decimal
        //var
        //    ItemUnitsOfMeasure: Record "Item Unit of Measure";
        begin
            TotalGrossWeight += LineWeight;
            LineWeightReturn := LineWeight;
        end;

        local procedure GetItemUnitSize(ItemNo: Code[20]; ItemUnit: Code[20]) Size: Text
        begin
            if ItemUnitOfMeasure.Get(ItemNo, ItemUnit)
            then begin
                Size :=
                Format(ItemUnitOfMeasure.Height) + ' x '
                + Format(ItemUnitOfMeasure.Width) + ' x '
                + Format(ItemUnitOfMeasure.Length);
            end;
        end;



        var
            TotalNetWeight: Decimal;
            TotalGrossWeight: Decimal;
            LineNetWeight: Decimal;
            LineGrossWeight: Decimal;
            ItemUnitOfMeasure: Record "Item Unit of Measure";
            LineUnitSize: Text;
    }

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans