Skip to main content
Question

Run Print Labels and Print Shipment Confirmation from one button

  • July 19, 2025
  • 4 replies
  • 95 views

I'm trying to create a button that will run both the Print Labels and Print Shipment Confirmation actions for a shipment. I found some examples in the Acumatica base code that look to run one action, then wait, then run another, but it's not working for me. Below is one of the code examples I'm trying. The order which they run doesn’t matter. Everything I’ve tried either doesn't run the second action, or doesn’t run either action. I think I'm having trouble because one returns files and the other runs a report. Any ideas on what to do?


 

public PXAction<SOShipment> printCombinedLabelShipmentConfirmation;

 [PXButton(CommitChanges = true), PXUIField(DisplayName = "Print Labels/Packing Slip", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]

 public virtual IEnumerable PrintCombinedLabelShipmentConfirmation(PXAdapter adapter)

 {



     var list = adapter.Get<SOShipment>().ToList();

 var key = Guid.NewGuid();

var printArgs = new PrintPackageFilesArgs

{

Shipments = list,

Adapter = adapter,

Category = PackageFileCategory.CarrierLabel

};

 Base.LongOperationManager.StartAsyncOperation(key, ct =>   Base.PrintPackageFiles(printArgs, ct));

 Base.LongOperationManager.WaitCompletion(key);

 Base.printShipmentConfirmation.Press();



return list;

}

 

4 replies

davidnavasardyan
Jr Varsity I
Forum|alt.badge.img+3

@jacobslotta06 

The main issue here is that both PrintPackageFiles and printShipmentConfirmation.Press() are trying to trigger file downloads or reports in the same request cycle, and Acumatica doesn’t allow multiple file streams to be returned in a single HTTP response.

What ends up happening is the first action executes, but the second one is silently skipped or suppressed, especially if it also tries to return a file or launch the report viewer.

To work around this, you can split the two actions into separate long operations. Here's how you can adjust your code:

public PXAction<SOShipment> printCombinedLabelShipmentConfirmation;

[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Print Labels/Packing Slip", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
public virtual IEnumerable PrintCombinedLabelShipmentConfirmation(PXAdapter adapter)
{
var list = adapter.Get<SOShipment>().ToList();
if (list.Count == 0) return list;

var key = Guid.NewGuid();

var printArgs = new PrintPackageFilesArgs
{
Shipments = list,
Adapter = adapter,
Category = PackageFileCategory.CarrierLabel
};

// Run first operation
Base.LongOperationManager.StartAsyncOperation(key, ct =>
{
Base.PrintPackageFiles(printArgs, ct);
});

Base.LongOperationManager.WaitCompletion(key);

// Queue the second operation separately
PXLongOperation.StartOperation(Base, () =>
{
var graph = PXGraph.CreateInstance<SOShipmentEntry>();
graph.Document.Current = graph.Document.Search<SOShipment.shipmentNbr>(list[0].ShipmentNbr);
graph.printShipmentConfirmation.Press();
});

return list;
}

This way, the label printing happens first, and after it's complete, the shipment confirmation report runs in a new operation, allowing the report viewer to open as expected.


  • Author
  • Freshman I
  • July 22, 2025

@davidnavasardyan It doesn’t look like this works. It skips the label printing and just runs the Shipment Confirmation report. Below is my code. My version is 24.121.0004 if that makes a difference. 

public PXAction<SOShipment> printCombinedLabelShipmentConfirmation;
[PXButton(CommitChanges = true), PXUIField(DisplayName = "Print Labels/Packing Slip", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
public virtual IEnumerable PrintCombinedLabelShipmentConfirmation(PXAdapter adapter)
{

var list = adapter.Get<SOShipment>().ToList();
if (list.Count == 0) return list;

var key = Guid.NewGuid();

var printArgs = new PrintPackageFilesArgs
{
Shipments = list,
Adapter = adapter,
Category = PackageFileCategory.CarrierLabel
};

// Run first operation
Base.LongOperationManager.StartAsyncOperation(key, async ct =>
{
// with/without await gives same issue
await Base.PrintPackageFiles(printArgs, ct);
});

Base.LongOperationManager.WaitCompletion(key);

// Queue the second operation separately
PXLongOperation.StartOperation(Base, () =>
{
var graph = PXGraph.CreateInstance<SOShipmentEntry>();
graph.Document.Current = graph.Document.Search<SOShipment.shipmentNbr>(list[0].ShipmentNbr);
graph.printShipmentConfirmation.Press();
});

return list;

}

 


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • September 24, 2025

Hi ​@jacobslotta06 were you able to find a solution? Thank you!


  • Author
  • Freshman I
  • November 14, 2025

Hi ​@jacobslotta06 were you able to find a solution? Thank you!

No I wasn’t. I was able to get it to work if you print the shipment confirmation to DeviceHub, but I wasn’t able to have it open the shipment confirmation report in a new window and print the labels. It only does one or the other depending on the order in code.