Skip to main content
Solved

Printing Packing Slip using Device Hub


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!

Best answer by Vignesh Ponnusamy

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.!

View original
Did this topic help you find an answer to your question?

9 replies

Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

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.!


  • Author
  • Freshman I
  • 5 replies
  • November 3, 2023

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:

 


Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

Hi @wjaved62,

I was able to publish the project in 23R106.

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


  • Author
  • Freshman I
  • 5 replies
  • November 3, 2023

I’m using 23R109.


  • Author
  • Freshman I
  • 5 replies
  • November 3, 2023

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. 


Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

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.!


  • Author
  • Freshman I
  • 5 replies
  • November 13, 2023

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?


lauraj46
Captain II
Forum|alt.badge.img+8
  • Captain II
  • 591 replies
  • December 7, 2023

Hi @wjaved62 ,

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

Thanks,

Laura


  • Author
  • Freshman I
  • 5 replies
  • December 7, 2023

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings