Skip to main content
Answer

Want to update the Item in the Database using Event

  • April 9, 2025
  • 4 replies
  • 169 views

I want to update the  InventoryItem  based on the logic How can I do it. and Refresh the UI  

if (row != null) {
         ALLInventory InventoryItem = PXSelect<ALLInventory, Where<ALLInventory.inventoryID, Equal<Required<ALLInventory.inventoryID>>>>.Select(e.Cache.Graph, row.InventoryID);

         if (InventoryItem != null) // Details related Material Allocation is available
         {  
         
                 // IF - Total Consuemd Qty + Order Oty <= Maximum Allocated Quantity
                 if(InventoryItem.TotalConsumedQty + row.OrderQty <= InventoryItem.MaxAllowedQty)
                 {
                     InventoryItem.TotalConsumedQty += (int?)row.OrderQty;

                 }
                 else // ELSE - Place Order for Total Consuemd Qty + Order Oty - Maximum Allocated Quantity
                 {
                     InventoryItem.TotalConsumedQty = InventoryItem.MaxAllowedQty;
                     row.OrderQty = InventoryItem.TotalConsumedQty + row.OrderQty - InventoryItem.MaxAllowedQty;
                 }

                 // Update the Inventory Item in the Database ------------------------------
             }

}
      

Best answer by davidnavasardyan

@anupusefulbi 

One of the options to update a database record in Acumatica is by using PXDatabase.Update. This provides a direct way to modify a record in the database.

So, if you need to update a value directly, you can use it like this:

PXDatabase.Update<MyTable>(new PXDataFieldParam[]
{
new PXDataFieldAssign(nameof(MyTable.Field), "FieldValue"),
new PXDataFieldRestrict(nameof(MyTable.Key1), "Key1Value"),
new PXDataFieldRestrict(nameof(MyTable.Key2), "Key2Value"),
});

This approach bypasses the DAC and graph logic, so be sure to use it carefully, especially when business logic or events (like RowUpdated) are involved.

4 replies

DipakNilkanth
Pro III
Forum|alt.badge.img+13

Hi ​@anupusefulbi,

What is ALLInventory  in your code? Have you created custom DAC named ALLInventory ?


Forum|alt.badge.img+8
  • Captain II
  • April 9, 2025

alongside ​@Nilkanth Dipak  comment, you can use e.Cache.SetValueExt<YourDAC.yourField>(row, YourValue) to update the DB.


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

@anupusefulbi 

One of the options to update a database record in Acumatica is by using PXDatabase.Update. This provides a direct way to modify a record in the database.

So, if you need to update a value directly, you can use it like this:

PXDatabase.Update<MyTable>(new PXDataFieldParam[]
{
new PXDataFieldAssign(nameof(MyTable.Field), "FieldValue"),
new PXDataFieldRestrict(nameof(MyTable.Key1), "Key1Value"),
new PXDataFieldRestrict(nameof(MyTable.Key2), "Key2Value"),
});

This approach bypasses the DAC and graph logic, so be sure to use it carefully, especially when business logic or events (like RowUpdated) are involved.


Forum|alt.badge.img+5
  • Jr Varsity I
  • April 11, 2025

Hi ​@anupusefulbi,

For updating inventory item:

           InventoryItemMaint itemGraph = PXGraph.CreateInstance<InventoryItemMaint>();
           InventoryItem item = PXSelect<InventoryItem,
Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(itemGraph, line.TSItem);

 

           if (item != null)
           {
               item.HSTariffCode = row.TSCommodity;
               itemGraph.Item.Update(item);
               itemGraph.Actions.PressSave();
           }

For refresh:

this.yourviewname.View.RequestRefresh();

Hope this helps!