Skip to main content

Notifications

Community site session details

Community site session details

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

Help with totalling on Word format Standard Sales Invoice extension

(1) ShareShare
ReportReport
Posted on by 8
Hi All,
 
I'm having trouble getting 2 added fields to total on a Word based extension of the Standard Sales Invoice.
 
I requirement is to show on invoice lines a carton qty - the customer sells in and the base unit of measure is units (but still ships in cartons and some customers order in cartons). Also there is a need to also show the total gross weight for all of the lines on the invoice in the footer - but no need to show on each line.
 
I have successfully added 2 fields for Units per Carton and Gross Weight to the Item master, a Code Unit to do the calculations required and then added fields for the results into Sales Line, Sales Invoice Line and the Sales Order subform so it is visible to the users at each stage through the order cycle.
 
I have successfully created a report extension to add the Cartons field to the invoice lines but no matter what I try I am unable to get the total for Cartons and Gross Weight in the footer - the fields are showing but with zero value - the code is below.
 
Thanks in advance for advice on what to do.
 
Stephen
 
reportextension 50100 MyExtension extends /Standard Sales - Invoice/
{
dataset
{
 
add(Line)
{
column(Line_Carton_Quantity; /Line Carton Quantity/) { }
column(Line_Gross_Weight; /Line Gross Weight/) { }
}
 
add(Header)
{
column(TotalLineCartonQuantity; TotalLineCartonQuantity) { }
column(TotalGrossWeight; TotalLineGrossWeight) { }
}
 
}
Local procedure AddToTotal(/Line Carton Quantity/: Integer; /Line Gross Weight/: Integer)
begin
LineCartonQuantity := /Line Carton Quantity/;
LineGrossWeight := /Line Gross Weight/;
PrevLineCartonQuantity += LineCartonQuantity;
PrevLineGrossWeight += /LineGrossWeight/;
TotalLineCartonQuantity += PrevLineCartonQuantity;
TotalLineGrossWeight += PrevLineGrossWeight;
end;
 
var
LineCartonQuantity: Integer;
LineGrossWeight: Integer;
TotalLineCartonQuantity: Integer;
PrevLineCartonQuantity: Integer;
TotalLineGrossWeight: Integer;
PrevLineGrossWeight: Integer;
}
 
 
  • Community member Profile Picture
    8 on at
    Help with totalling on Word format Standard Sales Invoice extension
    Thanks @Ariba Mehdi
     
    Everything on the invoice is working except for the Totals.
     
    The Line Carton Quantity is displaying correctly on each line and all other information about the invoice is also correct. It is purely a case of not being able to total the line carton quantity for each line displayed and then putting the total in the footer.
     
    It seems the Report Extension is limited in the triggers you can use - I have tried to put in a procedure to determine if its the first line, last line or somewhere in between but I cant use "Find" or "SetRange" in Report Extension syntax...
     
    I would have thought this would have been a pretty simple task given Microsoft authoring both Business Central and Word - hopefully the solution isn't to copy the full report definition and modify that as a custom report.
     
    Cheers
    Stephen
  • Suggested answer
    Ariba Mehdi Profile Picture
    160 on at
    Help with totalling on Word format Standard Sales Invoice extension
    Hi Stephen,
    If nothing works, we debug

    You can try to debug or print any message for this purpose in these procedures. Try to find out whether the report picks the correct Document No and Document Type or not.
    Also, check whether the values that are added to calculate the totals have correct values or not.
     
    Hope this helps! Good luck. 
  • Community member Profile Picture
    8 on at
    Help with totalling on Word format Standard Sales Invoice extension
    Thanks everyone for the responses - still not getting a calculation in the total fields.
     
    Hi @YUN ZHU - I can only find 2 triggers for a report extension - OnPreReport and OnPostReport - if I try to include these as you suggested then there is an error re the local procedure "the name local does not exist in the current context" ????
     
    Hi @KasparsSemjonovs - I have Total Carton Quantity and Total Gross Weight as fields added to the Header and they show up under the Header within the XML Mapping in Word and its there totals that are not being generated - there show on the report with zeroes.
     
     
    Hi @Ariba Mehdi - no success - I tried what you suggested, still zeroes.
     
    It seems that the combination of Word and ReportExtension is a bit of a challenge - especially for the inexperienced like me.
     
    Any more clues are greatly appreciated.
     
    ​​​​​​​Stephen
  • Suggested answer
    YUN ZHU Profile Picture
    83,072 Super User 2025 Season 1 on at
    Help with totalling on Word format Standard Sales Invoice extension
    Hi, you created a Local procedure AddToTotal but didn't put it in any trigger? This way the function will not run and all your fields will not be calculated. You can check the documentation below and put the code in the required trigger.
     
    Sorry, I haven't tested it in detail. You can try to put it in the OnPostDataItem Trigger of Line dataitem first.
     
     
    Hope this helps as well.
    Thanks.
    ZHU
  • Suggested answer
    KasparsSemjonovs Profile Picture
    4,209 Super User 2025 Season 1 on at
    Help with totalling on Word format Standard Sales Invoice extension
    Total cartons and Total Gross weight should not be on the Sales Lines, but on the Sales Header. Then You can use it outside the Lines area on the Word.
     
    Try to find where these Totals are defined for standard Sales Invoice
  • Suggested answer
    Ariba Mehdi Profile Picture
    160 on at
    Help with totalling on Word format Standard Sales Invoice extension
    Hi there,

    Try to make method calls like this.
    And return the value using exit.
    Also, apply appropriate filters using setfilters methods in the procedures to calculate correct values. 



     
    Hope this 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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 858

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 569

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans