Skip to main content
Solved

Store value in DB from event handler


param2022
Jr Varsity II
Forum|alt.badge.img

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

Best answer by Dioris Aguilar

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

 

View original
Did this topic help you find an answer to your question?

7 replies

Dioris Aguilar
Jr Varsity I
Forum|alt.badge.img+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?


param2022
Jr Varsity II
Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 94 replies
  • June 20, 2022

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


Dioris Aguilar
Jr Varsity I
Forum|alt.badge.img+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.


param2022
Jr Varsity II
Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 94 replies
  • June 20, 2022

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


Dioris Aguilar
Jr Varsity I
Forum|alt.badge.img+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();
			}

 


param2022
Jr Varsity II
Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 94 replies
  • June 20, 2022

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


Dioris Aguilar
Jr Varsity I
Forum|alt.badge.img+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.

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings