Skip to main content
Answer

Having a custom field show on generic inquiry after it is modified by event

  • May 7, 2025
  • 6 replies
  • 82 views

Forum|alt.badge.img

I have a custom field that interacts with a query to count the number of production order materials with negative quantity requirements. We are using this to indicate byproducts.

 

Here is the DAC for the custom field:

 

Here is the code for ProdMaint:

namespace PX.Objects.AM
{
public class ProdMaint_Extension : PXGraphExtension<PX.Objects.AM.ProdMaint>
{
public PXSelect<AMProdMatl, Where<AMProdMatl.orderType, Equal<Current<AMProdItem.orderType>>, And<AMProdMatl.prodOrdID, Equal<Current<AMProdItem.prodOrdID>>>>> ProdMaterials;

#region Event Handlers

protected void _(Events.RowSelected<AMProdItem> e)
{
AMProdItem row = e.Row;
if (row == null) return;

AMProdItem prodItem = (AMProdItem)Base.ProdMaintRecords.Current;
var amProdItemExtVar = PXCache<AMProdItem>.GetExtension<AMProdItemExt>(prodItem);

var inventoryIDletters = "";

foreach (AMProdMatl material in ProdMaterials.Select()) {
if(material.QtyReq < 0) {
inventoryIDletters += material.InventoryID.ToString().Substring(0, 1);
}
}
if (inventoryIDletters.Length != 0) {
e.Cache.SetValueExt<AMProdItemExt.usrNumOfByproducts>(row, inventoryIDletters.Length);
}else{
e.Cache.SetValueExt<AMProdItemExt.usrNumOfByproducts>(row, 0);
}
return;
}

#endregion
}
}

 

This is the current result of the Production Order Maintenance generic inquiry:

Most of these should have zero, AM001344 should have 1, but right now they are all blank.

 

Best answer by u662

I needed to update my cache after changing the database value.

 

Here is my final code:

using System;
using PX.Data;
using PX.Objects.IN;
using PX.Objects.CS;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using PX.Objects.AM.GraphExtensions;
using PX.Common;
using PX.Objects.Common;
using PX.Objects.SO;
using PX.Objects.AM.Attributes;
using System.Linq;
using PX.Objects.AM.CacheExtensions;
using PX.Data.BQL.Fluent;
using PX.Data.BQL;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.GL;
using PX.Objects;
using PX.Objects.AM;

namespace PX.Objects.AM
{
public class ProdMaint_Extension : PXGraphExtension<PX.Objects.AM.ProdMaint>
{

public PXSelect<AMProdMatl, Where<AMProdMatl.orderType, Equal<Current<AMProdItem.orderType>>, And<AMProdMatl.prodOrdID, Equal<Current<AMProdItem.prodOrdID>>>>> ProdMaterials;

#region Event Handlers

protected void AMProdItem_StatusID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (AMProdItem)e.Row;
if (row == null) return;

this.updateByproductCount();
}

public PXAction<PX.Objects.AM.AMProdItem> UpdateByproductCount;

[PXUIField(DisplayName = "Update Byproduct Qty", Visible = true)]
[PXButton(CommitChanges = true, DisplayOnMainToolbar = false, Category="Processing")]
protected void updateByproductCount()
{

AMProdItem prodItem = (AMProdItem)Base.ProdMaintRecords.Current;
var amProdItemExtVar = PXCache<AMProdItem>.GetExtension<AMProdItemExt>(prodItem);

var inventoryIDletters = "";

foreach (AMProdMatl material in ProdMaterials.Select() ) {
if(material.QtyReq < 0) {
inventoryIDletters += material.InventoryID.ToString().Substring(0, 1);
}
}
amProdItemExtVar.UsrNumOfByproducts = inventoryIDletters.Length;
Base.ProdMaintRecords.Update(prodItem);//cache is updated
Base.Save.Press();//save the updated cache
}

#endregion
}
}

 

6 replies

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

Hi ​@u662,

Have you checked whether your custom field is saving values to the database?
If it is being saved correctly in the database, it should also be visible in the Generic Inquiry (GI).


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • May 7, 2025

Hi ​@u662,

Have you checked whether your custom field is saving values to the database?
If it is being saved correctly in the database, it should also be visible in the Generic Inquiry (GI).

On a different environment with more production orders and the same code, there are some that do and don’t show up with numbers in the field. I suspect a saving issue of some kind.
 

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • May 7, 2025

Hi ​@u662,

Have you checked whether your custom field is saving values to the database?
If it is being saved correctly in the database, it should also be visible in the Generic Inquiry (GI).

On a different environment with more production orders and the same code, there are some that do and don’t show up with numbers in the field. I suspect a saving issue of some kind.
 

 

I made an action that just does a field update like so:
 


And for each form, it does correctly update the GI field:
 

​​​
Is it possible to recreate this field update in code?


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • May 8, 2025

Hi ​@u662,

Have you checked whether your custom field is saving values to the database?
If it is being saved correctly in the database, it should also be visible in the Generic Inquiry (GI).

I think the main thing that is happening is the AMProdItem form itself is preventing saving. I made a Force Save action, and all it does is call Save. This is the result. 

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • Answer
  • May 8, 2025

I needed to update my cache after changing the database value.

 

Here is my final code:

using System;
using PX.Data;
using PX.Objects.IN;
using PX.Objects.CS;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using PX.Objects.AM.GraphExtensions;
using PX.Common;
using PX.Objects.Common;
using PX.Objects.SO;
using PX.Objects.AM.Attributes;
using System.Linq;
using PX.Objects.AM.CacheExtensions;
using PX.Data.BQL.Fluent;
using PX.Data.BQL;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.GL;
using PX.Objects;
using PX.Objects.AM;

namespace PX.Objects.AM
{
public class ProdMaint_Extension : PXGraphExtension<PX.Objects.AM.ProdMaint>
{

public PXSelect<AMProdMatl, Where<AMProdMatl.orderType, Equal<Current<AMProdItem.orderType>>, And<AMProdMatl.prodOrdID, Equal<Current<AMProdItem.prodOrdID>>>>> ProdMaterials;

#region Event Handlers

protected void AMProdItem_StatusID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (AMProdItem)e.Row;
if (row == null) return;

this.updateByproductCount();
}

public PXAction<PX.Objects.AM.AMProdItem> UpdateByproductCount;

[PXUIField(DisplayName = "Update Byproduct Qty", Visible = true)]
[PXButton(CommitChanges = true, DisplayOnMainToolbar = false, Category="Processing")]
protected void updateByproductCount()
{

AMProdItem prodItem = (AMProdItem)Base.ProdMaintRecords.Current;
var amProdItemExtVar = PXCache<AMProdItem>.GetExtension<AMProdItemExt>(prodItem);

var inventoryIDletters = "";

foreach (AMProdMatl material in ProdMaterials.Select() ) {
if(material.QtyReq < 0) {
inventoryIDletters += material.InventoryID.ToString().Substring(0, 1);
}
}
amProdItemExtVar.UsrNumOfByproducts = inventoryIDletters.Length;
Base.ProdMaintRecords.Update(prodItem);//cache is updated
Base.Save.Press();//save the updated cache
}

#endregion
}
}

 


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • May 8, 2025

Thank you for sharing your solution with the community ​@u662!