There can be many blog posts about how to use 2D barcodes (QR codes, mainly) within Dynamics 365 Business Central but not that many are using an Invoice to demo them.
I will try to have this gap fixed at my style.
First things first.
Report (aka clone the report) or Report Extensions?
Report Extensions have the (big) advantages of
- Not cloning the entire report hence YOU do not have to maintain that entirely
- Not cloning the entire report hence a smaller AL file
- Not cloning the entire report hence… whatever else related to not cloning the entire report
If you have to simply printout one or more field header values (e.g. the invoice No. – e.g. Sales Header No. -) then a Report Extension is the right way to go. Silent, swift (and deadly), like the US Marines motto.
Few lines of code and you do not have to maintain the whole report, keep extension file smaller, etc. Simple as 1,2,3.
When it comes to let’s say print out
- Document No.
- Printing Date
- All Total Amounts Values
- Whatever else that is not a field bounded to a table (e.g. a global or local report variable)
Then it gets just a bit more complicated and it falls back to Amleth’s dilemma: to clone or not to clone?
Writing universal code, would lead in trying to use Report Extension as much as possible BUT if developing a Report Extension would require to re-calculate all totals only for the sake of having these printed in QR Code then this is a no go. This might have performance implications.
So that, to go straight to the point, the more data are needed to be stored in QR Code that are not directly bounded to a table data item, the higher are the chances to clone the original report and add QR Code there.
How to achieve that? (Considering 19.1 and W1 Localized version)
- Clone Report 1306 Standard Sales Invoice and its own RDL and Word Layout and renumber it like e.g. the following

- Create 2 global variables: BarcodeString and EncodedTotals as Text.

- In Header data item, remember to initialize them as per the following

- In ReportTotalsLine data item add the following OnAfterGetRecord trigger and its code

- In Totals data item add the 2 Columns needed to populate the dataset

and the following OnAfterGetRecord trigger and its code to generate the Barcode string and its equivalent encoded value

- And that is all the code needed in AL. Now, let’s add 2 plain text item in the Word Layout like the following.
NOTE: Be absolutely sure that EncodedTotals has IDAutomation2D fonts (exactly as it is written)

(NOTE: BarcodeString has been jus added to showcase what is encoded in the QR).
If you deploy this extension then you can run this directly using Tell Me feature or you could also think to add a simple codeunit that subscribe to OnAfterSubstituteReport event in ReportManagement codeunit as written officially in Substituting Reports - Business Central | Microsoft Docs.
Below a screenshot of the report output. Try out with your device to scan it.
