I have been going through the code required to print a label to a Zebra label printer in Acumatica. For those who are interested, below is the most minimal version of printing a label from DeviceHub using Acumatica Framework/C#. You can run this code in a PXAction, for example, in order to click a button and print a label. I have obfuscated the Guids, so that’s why they might look a little weird.
The FILEID GUID referenced in the CreatePrintJob call can reference any file that has been uploaded to Acumatica. You just need to figure out its GUID, which appears in the URL when you open the file (and there are a bunch of other ways to figure out the GUID as well, including looking inside the database). The printer GUID can also be grabbed from the database, or by making the appropriate method calls in C# (I don’t know how to get it out of the GUI at the moment).
Thanks to
My only problem with this whole paradigm is that it REQUIRES uploading a file to Acumatica. Some of the built in code that wraps these functions in Acumatica will also delete the file once its printed. So basically, we upload a zpl file to Acumatica, then call this method with a reference to the fileid, and then we destroy the zpl file.
Of course, wouldn’t it make more sense to be able to build a string on the fly, and send it to the printer? All the uploading and downloading of files creates a lot of delay in sending the file to the printer. The standard objection here might be...well what happens if DeviceHub is offline? Don’t you want your print job to execute when it comes back online? And my answer to this, with a focus on label printing in particular, is absolutely not. For some warehouses, they may want this. For us, if the label doesn’t arrive in 30 seconds, it may as well not arrive at all. We certainly don’t want it arriving, in bulk, 30 minutes later if DeviceHub has been offline for some reason (and even worse…. 2 days later in extreme cases...say a weekend outage). All this will do is cause the printer to kick out 100 untimely, useless labels that will have to be thrown away.
I don’t currently see a way to generate a string in code and send it to DeviceHub for printing, without an intervening file upload. Does anyone know of a way to do it?
Guid? printerID = Guid.Parse("D111111D-51CA-1BF1-1D11-111B11A1111D");
PrintSettings printSettings = new PrintSettings()
{
PrinterID = printerID,
NumberOfCopies = 1,
PrintWithDeviceHub = true,
DefinePrinterManually = false
};
PXGraph.CreateInstance<SMPrintJobMaint>().CreatePrintJob(printSettings, (string)null, new Dictionary<string, string> { { "FILEID", "11111f11-1d11-1111-a1d1-e1ef11bb1111" } }, "TEST PRINT");