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