We came across an interesting question on a Dynamics forum...
Question:
I am setting up custom labels for sales order line items for inventory purposes. We are using a Zebra label printer so I am setting up the ZPL script that will create the label each time the print button is selected. I found a useful line in the microsoft article about printing labels for all line items. But I am having trouble limiting that to just the line items that are selected, not all line items every time. The line in the ZPL script that prints one label per line item is as follows.
{{Row Table=/table name/ StartY=XXX IncY=XXX RowsPerLabel=1
How can I refine this to only print labels for the line items I have selected? I've tried looking for what kind of language or script this is coming from but I can't find anything that points me to how this is modifying the output.
Setting up custom labels for sales order line items is essential for inventory tracking and operational efficiency. If you're using a Zebra label printer, you can automate label generation by configuring ZPL scripts to trigger upon selecting the print button. However, the default behavior may print labels for all line items rather than just the selected ones. This guide will walk you through refining your ZPL script to ensure only the selected line items are printed.
Refining ZPL Script for Selected Line Items
The key to controlling label printing is utilizing the RowsPerLabel parameter effectively within the ZPL script. The original line in the script that prints one label per line item is:
{{Row Table=/table name/ StartY=XXX IncY=XXX RowsPerLabel=1}}
To refine this so that it prints only for selected line items, implement a custom filtering mechanism by leveraging electronic reporting and modifying the selection logic.
Implementation Approach
- Custom Selection Table
- Create a custom table to store selected sales order line items.
- When a sales line is selected and the custom button is clicked, a record is added to this table.
- The table will contain the necessary fields for ZPL label scripting.
- Electronic Reporting (ER) Configuration
- Use Electronic Reporting (ER) to generate ZPL output dynamically.
- Define a custom ER format that integrates with the selection table.
- Ensure the ER format is mapped correctly to fetch only selected line items.
- Form and UI Extensions
- Modify the sales order form to include a selection option.
- Add a button (Print Barcode) to trigger label printing for selected items.
- Implement a form extension to capture and process selections.
Code Implementation
Data Contract Class
Define a data contract class to manage label printing parameters:
[DataContractAttribute]
public class RYSE_BarcodeLabelsERContract extends ERFormatMappingRunBaseContract
{
DataMember("Site")
public InventSiteId parmSiteId(InventSiteId _siteId = siteId)
{
siteId = _siteId;
return siteId;
}
DataMember("Location")
public WMSLocationId parmLocationId(WMSLocationId _locationId = locationId)
{
locationId = _locationId;
return locationId;
}
}
Controller Class
Control the execution of label generation:
class RYSE_BarcodeLabelsERController extends ERFormatMappingRunBaseController
{
public static void main(Args args)
{
RYSE_BarcodeLabelsERController operation = new RYSE_BarcodeLabelsERController(
classStr(RYSE_BarcodeLabelsERService),
methodStr(RYSE_BarcodeLabelsERService, generateReportByGER),
SysOperationExecutionMode::Synchronous);
operation.startOperation();
}
}
Data Provider Class
Fetch and process selected sales order line items:
public void processRecords(RYSE_BarcodeLabelsERContract _contract)
{
barcodeLabelERTmp.clear();
this.getParametersFromContract(_contract);
while select retailInventItemLabelTable where retailInventItemLabelTable.Selected == true
{
this.insertTempTable(retailInventItemLabelTable);
}
}
UI Enhancements
- Modify the form to allow item selection.
- Add a button (Print Barcode) to trigger label printing.
- Extend the InventItemBarcodeLookup form to ensure only selected items are processed.
Configuring Electronic Reporting
- Create an ER Model
- Define data structure to match the custom table.
- Create Format Mapping
- Bind temporary table and contract class.

3. Define ZPL Label Format
Use the ER format designer to apply business logic for ZPL label printing.

4. Assign ZPL Printer as Destination
Ensure the electronic reporting destination is set to the Zebra label printer.
And that’s it! Please reach out if you have any questions, ZPL can be frustrating and we have a lot of experience wrestling with it. Contact us at community@rysetechnologies.com