Solved

Store value in DB from event handler

  • 18 June 2022
  • 7 replies
  • 223 views

Userlevel 2
Badge

I want to add value in DB for one of my DACExtension.

protected void ScanHeader_Barcode_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{

ScanHeader row = (ScanHeader)e.Row;
HeaderExt headerExt = row.GetExtension<HeaderExt>();
PickPackShip.Host graph = PXGraph.CreateInstance<PickPackShip.Host>();

SOShipment shipment = (from p in graph.Select<SOShipment>()
where
p.ShipmentNbr == row.Barcode
select p).FirstOrDefault();
if (shipment != null)
{
SOShipmentExt shipmentExt = shipment.GetExtension<SOShipmentExt>();
cache.SetValueExt<SOShipmentExt.myField>(shipment, headerExt.MyField);
}
}

I am trying like this but this is not working. My graph is not directly linked with SOShipment. My graph is PickPackShip.Host

icon

Best answer by Dioris Aguilar 20 June 2022, 16:46

View original

7 replies

Userlevel 5
Badge +2

@param2022 Yes, that’s right. Add the code to a custom action and get the shipmentNbr from the header or get the first line in the details which is SOShipLineSplit and this record will also have the shipmentNbr.

 

Userlevel 2
Badge

@Dioris Aguilar So I need to write this code in custom action ? As we in event handler it gives me error 
Error    “PX1043    Changes cannot be saved to the database from the event handler”

Userlevel 5
Badge +2

@param2022 You can use the following code to save the changes to DB: 
 

SOShipmentEntry shipmentEntry = PXGraph.CreateInstance<SOShipmentEntry>();
shipmentEntry.Document.Current = SelectFrom<SOShipment>.Where<SOShipment.shipmentNbr.IsEqual<@P.AsString>>.View.Select(shipmentEntry, shipmentNbr);

SOShipmentExt shipmentExt = shipment.GetExtension<SOShipmentExt>();
shipmentEntry.CurrentDocument.Cache.SetValueExt<SOShipmentExt.myField>(shipment, headerExt.MyField);

if (shipmentEntry.IsDirty)
{
shipmentEntry.Save.Press();
}

 

Userlevel 2
Badge

@Dioris Aguilar I don’t know how I can add those changes to DB. I will face same issue over there. I want to know how I can update Database values.

Userlevel 5
Badge +2

@param2022 I suggest to save the value in SOShipment using a custom PXAction and a custo smartpanel.
You would add a new PXAction in a graphExt for PickPackShip.Host and this custom action will call a custom smartpanel (popup window) (here’s a reference on how to create smartpanels https://asiablog.acumatica.com/2015/11/using-smart-panel.html), this popup window (smartpanel) will prompt for the value you want to save to SOShipment.

Userlevel 2
Badge

@Dioris Aguilar  yes I want to add that HeaderExtension’s value to the shipment that is being currently scanned. I am not getting shipment Id so I used barcode as last resort.

Userlevel 5
Badge +2

@param2022 I wouldn’t suggest to use the Barcode_FieldUpdated event for what you are trying to achieve since this field (Barcode) could be many things, not only Shipment Nbr: Shipment Nbr, Item, Location, etc..

It seems you have added a custom field in an extension (HeaderExt) at the header of PickPackShip and you want to copy that value to the selected shipment to another custom field (SOShipmentExt), am I right?

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