Skip to main content
Question

Want to update the Item in the Database using Event


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

}
      

4 replies

Nilkanth Dipak
Semi-Pro II
Forum|alt.badge.img+10

Hi ​@anupusefulbi,

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


Forum|alt.badge.img+8
  • Captain II
  • 399 replies
  • 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

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!


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