Getting the Shipment numbers from the posted sales invoice
Sometimes, you might want to print sales shipment information on a posted sales invoices. Because this is a one-to-many relationship – one sales invoice might be linked to many sales shipments and vice versa – you must get multiple records from the database.
Note: You can also use this article to get the invoices from the shipments. Just reverse the table numbers.
The first step is to add a JavaScript record for the sales shipment:
The next step is to read the records and store the information for use.
First add an array variable in the Header.OnPreDataItem trigger:
var shipments = []
Then add the script to read and store the shipments in the Header.OnAfterGetRecord trigger:
shipments = []
if (SalesShipmentHeader.FieldExtensions.No.HasValue) {
shipments.push({
no: SalesShipmentHeader.No,
shipmentDate: SalesShipmentHeader.ShipmentDate
})
}
while (SalesShipmentHeader.Next()) {
shipments.push({
no: SalesShipmentHeader.No,
shipmentDate: SalesShipmentHeader.ShipmentDate
})
}
Finally, we can use the collected information in a section. This line reads the shipment numbers and joins them with a new line character:
shipments.map(e => e.no).join(“n”);
Latest news
Latest knowledge base articles
-
AI Assistant in the ForNAV Designer (beta)
-
Mapping from Business Central documents to ZUGFeRD and XRechnung
-
Using native Business Central ZUGFeRD generation with FORNAV reports
-
Repeater tables and barcodes in the ForNAV Template Editor
-
Controlling report language, format region, copies, and watermark with the Report Settings page
