Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printer fails to receive job from DeviceHub

Tags:

c#

acumatica

I have the exact situation described in this question: Device Hub communication with printer queue

Due to the question having neither an accepted, nor an acceptable answer, I am asking the question again.

I have configured DeviceHub with Acumatica, and my printer is shown. I am sending the print job via a PXAction. Upon executing the action, DeviceHub logs the successful reception of the job, but the printer queue never receives it.

Here's my code, because this is StackOverflow:

public PXAction<PX.Objects.CR.BAccount> PrintAddressLabel;

[PXButton(CommitChanges=true)]
[PXUIField(DisplayName = "Print Label")]
protected void printAddressLabel()
{
  BAccount baccount = Base.Caches[typeof(BAccount)].Current as BAccount;
  string bAccountID = baccount.BAccountID.ToString();

  Dictionary<string, string> parameters = new Dictionary<string, string>();
  parameters["BAccountID"] = bAccountID;

  PXReportRequiredException ex = null;
  ex = PXReportRequiredException.CombineReport(ex, "ZRCRADDR", parameters);
  SMPrintJobMaint.CreatePrintJobGroup("DYMOLABEL", ex, "Address Label");
}

Could someone point me in a helpful direction?

EDIT:

Upon further testing, I found the following:

Acumatica will print successfully to my DeviceHub printer using the built in printing processes. However, when printing one of those jobs, the DeviceHub logs show a POLL event. When attempting to print from my code, DeviceHub records an NT event, which never makes it to the printer queue.

Upon further testing, in 2019 R1 the logs have changed slightly. Printing Invoices from Acumatica results in an NT event as well. However, there is one line different from a job created in Acumatica versus a job created in code.

Green = job from Acumatica

Orange = job from code

The line Printer DYMOLABEL - printing PDF to \\*printer* is missing in the job sent from code.

like image 412
Deetz Avatar asked Oct 15 '22 14:10

Deetz


1 Answers

If I understand correctly ,then you need to add report through Automation Steps screen and associate it with DeviceHub.
Example was written for Invoices,when the process will work under which need print Invoice, then will use these settings :

public class CustomEntry : PXGraph<CustomEntry>
{
 [PXQuickProcess.Step.IsBoundToAttribute(typeof(UsrPath.SO303000.Balanced.Report.PrintLabelReport), false)][PXQuickProcess.Step.RequiresStepsAttribute(typeof(SOQuickProcessParameters.prepareInvoice))]
 [PXQuickProcess.Step.IsInsertedJustAfterAttribute(typeof(SOQuickProcessParameters.prepareInvoice))]
 [PXQuickProcess.Step.IsApplicableAttribute(typeof(Where<Current<SOOrderType.behavior>, In3<SOOrderTypeConstants.salesOrder, SOOrderTypeConstants.invoiceOrder, SOOrderTypeConstants.creditMemo>, And<Current<SOOrderType.aRDocType>, NotEqual<ARDocType.noUpdate>>>))]
 protected virtual void SOQuickProcessParameters_PrintInvoice_CacheAttached(PXCache sender)
 {
 }
}
public static class UsrPath
{
 public static class SO303000
 {
    public static readonly Type GroupGraph = typeof(SOInvoiceEntry);
    public static class Balanced
    {
        public const string GroupStepID = "Balanced";
        public static class Report
        {
            public const string GroupActionID = "Report";
            public class PrintLabelReport : PXQuickProcess.Step.IDefinition
            {
                public Type Graph
                {
                    get
                    {
                        return UsrPath.SO303000.GroupGraph;
                    }
                }
                public string StepID
                {
                    get
                    {
                        return "Balanced";
                    }
                }
                public string ActionID
                {
                    get
                    {
                        return "Report";
                    }
                }
                public string MenuID
                {
                    get
                    {
                        return "Print Label";
                    }
                }
                public string OnSuccessMessage
                {
                    get
                    {
                        return "<Invoice form> is prepared";
                    }
                }
                public string OnFailureMessage
                {
                    get
                    {
                        return "Preparing Invoice form";
                    }
                }
            }
        }
     }
  }
}  

Updated answer

 public PXAction<BAccount> PrintAddressLabel;
    [PXButton(CommitChanges = true)]
    [PXUIField(DisplayName = "Print Label")]
    protected virtual IEnumerable printAddressLabel(PXAdapter adapter)
    {
        List<BAccount> list = adapter.Get<BAccount>().ToList<BAccount>();
        int? branchID = this.Base.Accessinfo.BranchID;
        const string reportID = "YOUR_REPORT_ID";
        Dictionary<string, string> dictionary = new Dictionary<string, string>();
        Dictionary<string, PXReportRequiredException> dictionary2 = new Dictionary<string, PXReportRequiredException>();
        PXReportRequiredException ex = null;
        foreach (BAccount account in list)
        {
            dictionary["BAccountID"] = account.AcctCD;
            ex = PXReportRequiredException.CombineReport(ex, null, dictionary);
            object row = PXSelectorAttribute.Select<BAccount.bAccountID>(this.Base.BAccount.Cache, account);
            string text = new NotificationUtility(this.Base).SearchReport(null, row, reportID, branchID);
            //I think you get this problem due to absence of this line
            PrintParameters printParams = new PrintParameters
            {
                PrintWithDeviceHub = true,
                DefinePrinterManually = true,
                PrinterName = "DYMOLABEL"
            };
            dictionary2 = SMPrintJobMaint.AssignPrintJobToPrinter(dictionary2, dictionary, printParams, new NotificationUtility(this.Base).SearchPrinter, null, reportID, reportID, this.Base.Accessinfo.BranchID);
        }
        if (ex != null)
        {
            SMPrintJobMaint.CreatePrintJobGroups(dictionary2);
            throw ex;
        }
        return adapter.Get();
    }

    [Serializable]
    [PXCacheName("Print Parameters")]
    public partial class PrintParameters : IBqlTable, IPrintable
    {
        #region PrintWithDeviceHub
        [PXDBBool]
        [PXDefault(typeof(FeatureInstalled<FeaturesSet.deviceHub>))]
        public virtual bool? PrintWithDeviceHub { get; set; }
        public abstract class printWithDeviceHub : IBqlField { }
        #endregion

        #region DefinePrinterManually
        [PXDBBool]
        [PXDefault(true)]
        public virtual bool? DefinePrinterManually { get; set; }
        public abstract class definePrinterManually : IBqlField { }
        #endregion

        #region PrinterName
        [PXPrinterSelector]
        public virtual string PrinterName { get; set; }
        public abstract class printerName : IBqlField { }
        #endregion
    }  

Configuration of the Device Hub

like image 86
Vardan Vardanyan Avatar answered Oct 21 '22 05:10

Vardan Vardanyan