Solved

How can I update a checkbox on the attributes tab when the sales category changes?

  • 15 September 2023
  • 3 replies
  • 89 views

Userlevel 5
Badge +1

I have a created a custom field which I want to use to track when the item sales categories have changed. See image below:

I added code to field verifying:

protected void INItemCategory_CategoryID_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e, PXFieldVerifying InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (INItemCategory)e.Row;

if (row == null) return;

PXTrace.WriteInformation("Set BC Updated");
// Update the BC Updated field to false
try {
InventoryItem inventoryItem = PXSelect<
InventoryItem,
Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>
>>.Select(Base, ((PX.Objects.IN.INItemCategory)cache.Current).InventoryID);

if (inventoryItem != null) {
PXTrace.WriteInformation("InventoryItem found" + inventoryItem.InventoryID);
}
InventoryItemExt invItemExt = PXCache<InventoryItem>.GetExtension<InventoryItemExt>(inventoryItem);
invItemExt.UsrAIBCCatAdded = false;
PXTrace.WriteInformation("Updated");
}
catch (Exception error) {
PXTrace.WriteInformation("Error: " + error);
}
}

I’m probably doing this completely incorrectly.  I think my main problem is I don’t know how to get the actual custom field on the screen to update (in the cache I guess).

Any help would be much appreciated.

 

Thanks in advance,

 

Phil

icon

Best answer by darylbowman 15 September 2023, 20:53

View original

3 replies

Userlevel 5
Badge +3
  1. Give C# code of DAC class which contains that field
  2. Why you use FieldVerifying event?
  3. Give also view you use for DAC class, which contains field
Badge +11

FieldVerifying is meant to be used to verify a value being saved and be able to cancel it under certain circumstances. Since that’s not really what you’re needing, I would use FieldUpdated.

protected virtual void _(Events.FieldUpdated<INItemCategory, INItemCategory.categoryID> e)
{
INItemCategory row = e.Row;
if (row is null) return;

Since you’re working in the InventoryItemMaint graph, you can use e.Cache.Graph to get the current graph instance and then grab the current InventoryItem from the graph instead of selecting again (although that would work).

var inventoryItemGraph = e.Cache.Graph as InventoryItemMaint;
InventoryItem item = inventoryItemGraph.Item.Current;
if (item is null) return;

Then, since you have the graph instance, you can just kindly request that your field be updated with the new value.

(I couldn’t tell from your code if you wanted this value to be true or false)

// Set the checkbox value
inventoryItemGraph.Item.SetValueExt<InventoryItemExt.usrAIBCCatAdded>(item, true);

 

Here’s the whole thing:

public class InventoryItemMaint_Extension : PXGraphExtension<PX.Objects.IN.InventoryItemMaint>
{
#region Event Handlers

protected virtual void _(Events.FieldUpdated<INItemCategory, INItemCategory.categoryID> e)
{
INItemCategory row = e.Row;
if (row is null) return;

var inventoryItemGraph = e.Cache.Graph as InventoryItemMaint;
InventoryItem item = inventoryItemGraph.Item.Current;
if (item is null) return;

// Set the checkbox value
inventoryItemGraph.Item.SetValueExt<InventoryItemExt.usrAIBCCatAdded>(item, true);
}

#endregion
}

 

Userlevel 5
Badge +1

@darylbowman Thanks so much, that’s perfect. I put it in the wrong event by mistake.  I did mean to put it in fieldupdated. I knew there was a better way of getting the inventoryitem to update but when trying to debug it that is all I could come up with. I wanted it to set to false as it needs to be set to false initially and will be set to true by another process. It needs to be false when that process needs to re-check for a change in sales categories also hence this customization.

Thanks also to @Yuriy Zaletskyy for answering too.

Phil

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