Solved

What is the best practice to send a custom report to DeviceHub and update a field in to show that it has been printed?

  • 16 January 2023
  • 3 replies
  • 342 views

Userlevel 7
Badge +7

Developer gurus,

What is the best practice to send a custom report to DeviceHub and update a field to show that it has been printed?

We have a custom Workflow Action that prints a custom report (labels) from the Production Order Maintenance screen.  The action opens the report on the screen and uses the “Field Updates” tab to update the IsReportPrinted field.

Now instead of printing to the screen, we would like to print this report directly using DeviceHub.  Is there any way in the Low Code/NoCode framework to do this?

I think we have some working code based on a very helpful thread and the response by @Gabriel Michaud, but I’m just wondering is there any way to accomplish this using the new workflow engine?  We hope to build in such a way that this will upgrade easily as Acumatica makes advancements to the workflow engine.

Code is based on the example attached to this thread:

 

using System;
using PX.Data;
using PX.Objects.IN;
using PX.Objects.CS;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using PX.Objects.AM.GraphExtensions;
using PX.Common;
using PX.Objects.Common;
using PX.Objects.SO;
using PX.Objects.AM.Attributes;
using System.Linq;
using PX.Objects.AM.CacheExtensions;
using PX.Objects.PO;
using PX.Data.BQL.Fluent;
using PX.Data.BQL;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Data.WorkflowAPI;
using PX.Objects;
using PX.Objects.AM;
using PX.SM;

namespace PX.Objects.AM
{
public class ProdMaint_Extension : PXGraphExtension<PX.Objects.AM.ProdMaint>
{
#region Event Handlers
public PXSelect<AMProdItem, Where<AMProdItem.orderType, Equal<Optional<AMProdItem.orderType>>>> ProdMaintRecords;

public PXSave<PX.Objects.AM.AMProdItem> Save;

public PXAction<PX.Objects.AM.AMProdItem> Printer;

[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Print Label to Device Hub")]
protected void printer()
{
SMPrinter printer = PXSelect<SMPrinter,
Where<SMPrinter.printerName, Equal<Required<SMPrinter.printerName>>>>.Select(Base, "BROTHER");

AMProdItem doc = ProdMaintRecords.Current;
Dictionary<string, string> parametersDictionary = new Dictionary<string, string>();
string actualReportID = "AM625099";

parametersDictionary["ProdOrdID"] = doc.ProdOrdID;
parametersDictionary["OrderType"] = doc.OrderType;

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


PXGraph.CreateInstance<SMPrintJobMaint>().CreatePrintJob(printSettings, actualReportID, parametersDictionary, "label report");

doc.IsReportPrinted = true;
ProdMaintRecords.Update(doc);
Save.Press();

}
#endregion

}
}

Laura

icon

Best answer by Yuriy Zaletskyy 21 January 2023, 11:58

View original

3 replies

Userlevel 5
Badge +3

The best practice to send a custom report to DeviceHub and update a field to show that it has been printed in Acumatica ERP would be to use the Acumatica workflow engine to automate the process.

Here is an example of how you can do this:

  1. Create a new custom workflow step that is triggered when the Production Order Maintenance screen is opened.
  2. In the custom workflow step, check the value of the "IsReportPrinted" field. If it is set to false, then send the report to DeviceHub using the SMPrintJobMaint graph and the PrintSettings class.
  3. Update the "IsReportPrinted" field to true to indicate that the report has been printed.
  4. Update the Production Order record with the new value of the "IsReportPrinted" field.

This way, the report will be automatically sent to DeviceHub and the "IsReportPrinted" field will be updated every time the Production Order Maintenance screen is opened, and the report hasn't been printed yet.

Here is the C# code for custom workflow step:

using PX.Data.WorkflowAPI;
using PX.Objects;
using PX.Objects.AM;
using PX.SM;
using System.Collections.Generic;

namespace PX.Objects.AM
{
public class ProdMaint_Workflow : PXGraph<ProdMaint_Workflow>
{
public PXCancel<AMProdItem> Cancel;
public PXAction<AMProdItem> print;
public PXSelect<AMProdItem> ProdMaintRecords;

[PXUIField(DisplayName = "Print Label to Device Hub")]
[PXButton]
public virtual IEnumerable Print(PXAdapter adapter)
{
AMProdItem doc = ProdMaintRecords.Current;

if (!doc.IsReportPrinted)
{
// Send report to Device Hub
SMPrinter printer = PXSelect<SMPrinter,
Where<SMPrinter.printerName, Equal<Required<SMPrinter.printerName>>>>.Select(this, "BROTHER");

Dictionary<string, string> parametersDictionary = new Dictionary<string, string>();
string actualReportID = "AM625099";

parametersDictionary["ProdOrdID"] = doc.ProdOrdID;
parametersDictionary["OrderType"] = doc.OrderType;

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

PXGraph.CreateInstance<SMPrintJobMaint>().CreatePrintJob(printSettings, actualReportID, parametersDictionary, "label report");

// Update the IsReportPrinted field
doc.IsReportPrinted = true;
ProdMaintRecords.Update(doc);
}

return adapter.Get();
}
}
}

that would by my suggestion, also some specific business needs I’ve ommited.

Userlevel 5
Badge +3

The code you provided is a good starting point, but the best practice would be to move the code that sends the report to DeviceHub and updates the "IsReportPrinted" field to a workflow step, rather than an event handler in the custom graph extension.

Userlevel 7
Badge +7

Hi @Yuriy Zaletskyy ,

Thank you so much for sharing this advice and sample code!   

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