Solved

Printing Packing Slip using Device Hub

  • 3 November 2023
  • 9 replies
  • 178 views

Userlevel 1

I’m trying to create an Action button on Shipments screen that would automatically print the Packing Slip to a particular printer. I’ve the following code added to the SOShipmentEntry:

 

namespace PX.Objects.SO
{

public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
{

#region Event Handlers

public PXAction<SOShipment> print;

[PXUIField(DisplayName = "Print Packing Slip with DeviceHub")]
[PXButton]
public virtual IEnumerable Print(PXAdapter adapter)
{
SOShipment shipment = Base.Document.Current;

Dictionary<string, string> parametersDictionary = new Dictionary<string, string>();
parametersDictionary["ShipmentNbr"] = shipment.ShipmentNbr;

PrintSettings printSettings = new PrintSettings()
{
PrinterID = "PACKINGSLIP1",
NumberOfCopies = 1,
PrintWithDeviceHub = true,
DefinePrinterManually = true
};

PXGraph.CreateInstance<SMPrintJobMaint>().CreatePrintJob(printSettings,"SO642000",parametersDictionary,"Packing Slip");

return adapter.Get();
}
#endregion
}
}

 

I get the following errors when I validate the code:
 

 

I can bypass the first error “Cannot implicitly convert type string to System.Guid?” by specifying printerID as the default printer set up on the user profile, but that doesn’t get rid of the second error where it says “No overload for method ‘CreatePrintJob’ takes 4 arguments”. 

 

I’ll appreciate any help!

icon

Best answer by Vignesh Ponnusamy 3 November 2023, 18:31

View original

9 replies

Userlevel 7
Badge +4

Hi @wjaved62,

I see you are setting PrinterID = "PACKINGSLIP1", where as PrinterID is type Guid

If you already have configured the Printer setting, you can do a BQL, get the Guid and use it in the PrintSettings. Below is an example implementation you can refer to,

            SMPrinter printer = PXSelect<SMPrinter, Where<SMPrinter.printerName,
Equal<Required<SMPrinter.printerName>>>>.Select(Base, "PACKINGSLIP1");
PrintSettings printSettings = new PrintSettings()
{

PrinterID = printer.PrinterID,
NumberOfCopies = 1,
PrintWithDeviceHub = true,
DefinePrinterManually = true
};

Happy Coding.!

Userlevel 1

Hi @Vignesh Ponnusamy ,

 

Thanks for your response, but I’ve already tried that with no luck. I tried it again and got the same error. Below is my new code:

public PXAction<SOShipment> print;

[PXUIField(DisplayName = "Print Packing Slip with DeviceHub")]
[PXButton]
public virtual IEnumerable Print(PXAdapter adapter)
{
SOShipment shipment = Base.Document.Current;

Dictionary<string, string> parametersDictionary = new Dictionary<string, string>();
parametersDictionary["ShipmentNbr"] = shipment.ShipmentNbr;

SMPrinter printer = PXSelect<SMPrinter, Where<SMPrinter.printerName,
Equal<Required<SMPrinter.printerName>>>>.Select(Base, "PACKINGSLIP1");

PrintSettings printSettings = new PrintSettings()
{
PrinterID = printer.PrinterID,
NumberOfCopies = 1,
PrintWithDeviceHub = true,
DefinePrinterManually = true
};

PXGraph.CreateInstance<SMPrintJobMaint>().CreatePrintJob(printSettings,"SO642000",parametersDictionary,"Packing Slip");

return adapter.Get();
}

And I still get the following error:

 

Below you can see the printer that I have set up for testing:

 

Userlevel 7
Badge +4

Hi @wjaved62,

I was able to publish the project in 23R106.

Can you please confirm the Acumatica version and build you are using?

Userlevel 1

I’m using 23R109.

Userlevel 1

It seems that the printer is being returned as null. I just realized that the “Active” checkbox isn’t checked on Printers screen, and that could be the reason. I was hoping that I would be able to test the code before actually configuring a printer, but it seems that has to be done first. 

Userlevel 7
Badge +4

I also think the signature of the method isn’t matching causing the issue, you can try the following and see if that helps.

PXGraph.CreateInstance<SMPrintJobMaint>().CreatePrintJob(SMPrintJobMaint.GetPrintSettings(adapter), "SO642000", parametersDictionary, "Packing Slip", cancellationToken);

Good Luck.!

Userlevel 1

I was dead wrong in my previous answer. I cannot get the code to validate. I tried your suggestion as well and I’m still getting the same error. Any other ideas?

Userlevel 7
Badge +7

Hi @wjaved62 ,

Were you able to get this working?  I am seeing the same error message.

Thanks,

Laura

Userlevel 1

Yes, I got it to work. 

Starting with 2023 R1, a fourth parameter is needed. Here is the sample code:

PXGraph.CreateInstance<SMPrintJobMaint>().CreatePrintJob(printSettings,"SO642000",parametersDictionary,"Packing Slip", CancellationToken.None);

Make sure to include the following namespace:

using System.Threading;

 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved