Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Info | ||
---|---|---|
| ||
Mobile WMS Extension version 5.14 or later. |
Case
Excerpt |
---|
Print your own ZPL labels |
Proposed solution
- You want to print ZPL labels from the mobile device
- You must generate the needed ZPL yourself. You can use ZPL Designer or ZebraDesigner to create the template you need.
- You do not want to use the integrated Cloud Print Service solution
See also:
How-to: Create custom Unplanned function in Main Menu
Step 1: Create Header
Add the following code to create your new header.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Reference Data", 'OnGetReferenceData_OnAddHeaderConfigurations', '', true, true)]
procedure MyOnGetReferenceData_OnAddHeaderConfigurations(var _HeaderFields: Record "MOB HeaderField Element")
begin
with _HeaderFields do begin
// Header Name
InitConfigurationKey('MyPrintLabelHeader');
// Input fields on the label
Create_TextField_ItemNumber(10);
Create_TextField_LotNumber(20);
Create_DateField_ExpirationDate(30);
Create_IntegerField_Quantity(40);
// Printer list
Create_ListField(50, 'Printer');
Set_label('Printer:');
Set_listValues('Printer A IP;Printer B MAC');
Set_clearOnClear(false);
Set_acceptBarcode(false);
// Number of Labels
Create_IntegerField(60, 'NumberOfLabels');
Set_label('Number of labels:');
Set_clearOnClear(true);
Set_acceptBarcode(false);
Set_defaultValue(1);
Set_minValue(0);
Set_maxvalue(10);
end;
end;
Step 2: Modify mobile config
You need let the Mobile configuration know that your new function and header is available.
Add the following to the Mobile Configuration Files to create a new page, a main menu icon as well as an action
Define a new Unplanned Function -page
Code Block language xml theme Eclipse <page id="MyPrintLabel" type="UnplannedItemRegistration" icon="mainmenucount-unplanned"> <title defaultValue="My print label page"/> <unplannedItemRegistrationConfiguration type="MyPrintLabel" useRegistrationCollector="false"> <header configurationKey="MyPrintLabelHeader"/> </unplannedItemRegistrationConfiguration> </page>
Add Icon to main menu for the unplanned function
Code Block language xml theme Eclipse <menuItem id="MyPrintLabel" displayName="MyPrintLabel" icon="mainmenuprint" alwaysEnabled="true"/>
Add action to context menu. We use Receive.
Code Block language xml theme Eclipse ...</orderListConfiguration> <actions> <open id="MyPrintLabel" title="Print my labels" icon="mainmenuprint"> </open> </actions>
Step 3: Handle posting / Generate ZPL
When the Header has been accepted a final request is made to "Post" the information ("PostAdhocRegistration").
In this step you must read the collected values and create the ZPL.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Adhoc Registr.", 'OnPostAdhocRegistrationOnCustomRegistrationTypeAsXml', '', true, true)]
procedure OnPostAdhocRegistrationOnCustomRegistrationTypeAsXml(var _XMLRequestDoc: XmlDocument; var _XMLResponseDoc: XmlDocument; _RegistrationType: Text; var _RegistrationTypeTracking: Text[200]; var _IsHandled: Boolean)
var
Item: Record Item;
TempHeaderFilter: Record "MOB NS Request Element" temporary;
MOBToolbox: Codeunit "MOB Toolbox";
MobWmsLanguage: Codeunit "MOB WMS Language";
MobRequestMgt: Codeunit "MOB NS Request Management";
XMLResponseData: XmlNode;
Status: Text;
PrintCommand: Text;
LotNo: Text;
ItemNumber: Text;
Printer: Text;
PrinterAddress: Text[50];
ExpirationDate: Date;
Quantity: Decimal;
NoOfLabels: Decimal;
begin
if _RegistrationType = 'MyPrintLabel' then begin
MobRequestMgt.SaveAdhocFilters(_XMLRequestDoc, TempHeaderFilter);
// Read the request field values
ItemNumber := TempHeaderFilter.GetValue('ItemNumber');
LotNo := TempHeaderFilter.GetValue('LotNo');
Printer := TempHeaderFilter.GetValue('Printer');
Quantity := TempHeaderFilter.GetValueAsDecimal('Quantity');
NoOfLabels := TempHeaderFilter.GetValueAsDecimal('NoOfLabels');
ExpirationDate := TempHeaderFilter.GetValueAsDate('ExpirationDate');
Item.Get(ItemNumber);
// Generate your ZPL
PrintCommand += '^XA';
PrintCommand += '^FO50,50^ADN,54,30^FD' + Item.Description + '^FS';
PrintCommand += '^FO50,130^BCN,100,Y,N,N^FD' + ItemNumber + '^FS';
PrintCommand += '^FO50,280^ADN,54,30^FDQty: ' + FORMAT(Quantity, 0, 9) + '^FS';
PrintCommand += '^FO50,380^ADN,54,30^FDExp: ' + FORMAT(ExpirationDate, 0, 9) + '^FS';
PrintCommand += '^FO50,500^ADN,54,30^FDLOT: ^FS';
PrintCommand += '^FO200,470^BCN,100,Y,N,N^FD' + LotNo + '^FS';
PrintCommand += '^PQ' + FORMAT(NoOfLabels) + ',0,0,';
PrintCommand += '^XZ';
// Convert printer name to a network address
case Printer of
'Printer A IP':
PrinterAddress := '1921681010';
'Printer B MAC':
PrinterAddress := '00225832FDAB';
end;
// Create print response to mobile device
MOBToolbox.InitializeResponseDocWithDesc(_XMLResponseDoc, XMLResponseData, MobWmsLanguage.GetMessage('PRINT_RESPONSE'));
MOBToolbox.AddZPLPrintCommandToRequest(XMLResponseData, PrinterAddress, PrintCommand);
Status := 'OK';
_IsHandled := true;
end;
end;
Step 4: Respond with ZPL
The mobile device will issue the print.
The XML response should look like this:
Code Block | ||||
---|---|---|---|---|
| ||||
<?xml version="1.0" encoding="UTF-8"?> <response xmlns="http://schemas.microsoft.com/Dynamics/Mobile/2007/04/Documents/Response" messageid="89CF29D1-941A-4459-8767-B83203C67355" status="Completed"> <description>Print OK</description> <responseData xmlns="http://schemas.taskletfactory.com/MobileWMS/BaseDataModel"> <print xmlns=""> <printerType>Zebra</printerType> <printerAddress>1921681010</printerAddress> <printCommand>^XA^FO50,50^ADN,54,30^FDIntense Orange^FS^FO50,130^BCN,100,Y,N,N^FDtf-002^FS^FO50,280^ADN,54,30^FDQty: 1^FS^FO50,380^ADN,54,30^FDExp: 2020-03-24^FS^FO50,500^ADN,54,30^FDLOT: ^FS^FO200,470^BCN,100,Y,N,N^FD^FS^PQ0,0,0,^XZ</printCommand> </print> </responseData> </response> |
The main menu icon
The header fields