Skip to main content
Solved

Updating the Stock Item from the Kit Assembly?

  • 21 October 2023
  • 2 replies
  • 82 views

Good day every one,

In my customization I have extended the KitAssemblyEntry (KitAssemblyEntry_Extension) and added an event handler to the release action:

 [PXOverride]
public PXAction<INKitRegister> release;
[PXProcessButton(CommitChanges = true)]
[PXUIField(DisplayName = Messages.Release, MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
public virtual IEnumerable Release(PXAdapter adapter)
{
//Base.Document.Ask("Application date does not equal to Business date, do you really want to release payment?", MessageButtons.OK);
INKitRegister kitRegister = (INKitRegister)Base.Caches[typeof(INKitRegister)].Current;
InventoryItem inventoryItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(Base, kitRegister.KitInventoryID);

inventoryItem.Descr = "Update from Kit Assembly";
// Update the InventoryItem in the database
Base.Caches[typeof(InventoryItem)].Update(inventoryItem);

// Save changes to the database
Base.Actions.PressSave();

//return adapter.Get();
return Base.release.Press(adapter);
}

I am trying to update the Stock Item (InventoryItem) from the Kit Assembly when the Release action is pressed?

I am not sure why this is not working?

Thanks

2 replies

I found the issue - I was using the actual DAC instead of the name.

Here is a cleaner version of this code:

 

InventoryItem inventoryItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(Base, kitRegister.KitInventoryID);

inventoryItem.Descr = "Update from Kit Assembly";

PXCache cache = Base.Caches[typeof(InventoryItem)];
cache.Update(inventoryItem);
cache.Persist(inventoryItem, PXDBOperation.Update);

 

Userlevel 7
Badge

Thank you for sharing your solution with the community @DewaldH!

Reply