Solved

Cannot get PXDefault in my DAC to show on the screen

  • 10 April 2024
  • 7 replies
  • 72 views

Userlevel 6
Badge +3

I have a custom unbound field on the Kit Specifications grid UsrQtyOnHand.  

	public class INKitSpecStkDetExtCummings : PXCacheExtension<PX.Objects.IN.INKitSpecStkDet>
{
#region UsrQtyOnHand
[PXDecimal]
[PXUIField(DisplayName = "Qty On Hand", Enabled = false)]

[PXDefault(typeof(Search<INItemStats.qtyOnHand,
Where<INItemStats.inventoryID, Equal<Current<INKitSpecStkDet.compInventoryID>>>>),
PersistingCheck = PXPersistingCheck.Nothing)]
[PXFormula(typeof(Sum<INItemStats.qtyOnHand>))]

public virtual Decimal? UsrQtyOnHand { get; set; }
public abstract class usrQtyOnHand : PX.Data.BQL.BqlDecimal.Field<usrQtyOnHand> { }
#endregion
}

I want to go to the INItemStats table and pull the QtyOnHand value for the current inventory id on the grid line.

I can do it in the row selected handler, but I don’t know why my PXDefault is not working.

I added a PXFormula but that didn’t help.

What am I doing wrong?

icon

Best answer by Leonardo Justiniano 10 April 2024, 22:44

View original

7 replies

Userlevel 6
Badge +4

Hi @Joe Schmucker 

Has been a while! You can add a FieldDefaulting event and do your BQL query there. The formula itself won’t help. When you add [PXDefault] attribute on your custom field, it will trigger that FieldDefaulting event. Also make sure that you to assign values using SetValueEx as it triggers any formula on related fields you are modifying in that processing.

 

Hope this helps.

Badge +11

The defaulting event would need to fire after the CompInventoryID has changed. In order to do this, add

[PXFormula(Default<INKitSpecStkDet.compInventoryID>)]

to the UsrQtyOnHand definition which will cause the defaulting event to fire whenever CompInventoryID changes.

Userlevel 6
Badge +3

@darylbowman when I put in the formula I get a compiler error.  I never use formulas (at least very rarely) and I don’t even know what to try to fix it.

Based on your advice and @Leonardo Justiniano , I think I’ve done what you guys suggested.  

Do I still need to do the search in the PXDefault statement?

Userlevel 6
Badge +3

@darylbowman 

I’m getting a compiler error.  Any idea what I should change?

 

Badge +11

Sorry, try this:

[PXFormula(typeof(Default<INKitSpecStkDet.compInventoryID>))]

Userlevel 6
Badge +3

I need a demotion.  I do not deserve Captain II.  

My field defaulting only fires when you add a new line and select an inventory item. 

I need the fields to be populated when you pull up an existing Kit item.  It seems as though the field is not being evaluated as updated when the grid is populated when you select the kit.

I tried adding another method to trigger the field updated events when the grid is populated but it isn’t firing either:

        protected void INKitSpecStkDet_CompInventoryID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
var row = (INKitSpecStkDet)e.Row;
object dummy;
cache.RaiseFieldDefaulting<INKitSpecStkDetExtCummings.usrQtyOnHandB>(row, out dummy);
cache.RaiseFieldDefaulting<INKitSpecStkDetExtCummings.usrQtyOnHandC>(row, out dummy);
}

protected void INKitSpecStkDet_UsrQtyOnHandB_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
var row = (INKitSpecStkDet)e.Row;
decimal? qty = 0m;

INKitSpecStkDetExtCummings ext = row.GetExtension<INKitSpecStkDetExtCummings>();
if (ext == null) return;

//B
//60 for prod 7 for dev
INItemStats iNItemStatsB = SelectFrom<INItemStats>.Where<INItemStats.inventoryID.IsEqual<@P.AsInt>
.And<INItemStats.siteID.IsEqual<@P.AsInt>>>.View.Select(Base, row.CompInventoryID, 7);
if (iNItemStatsB != null) qty = iNItemStatsB.QtyOnHand;

//cache.SetValueExt<INKitSpecStkDetExtCummings.usrQtyOnHandB>(row, qty);
ext.UsrQtyOnHandB = qty;
}

FYI, your suggestions work when you are adding a new line to the grid, but not when it is being filled in at the start of the page.

It seems like I’m back to working with a row selected handler.  It isn’t really a big deal as there aren’t that many items in the kits so performance isn’t really affected.  I just want to do things the right way.

 

Badge +11

If you're trying to populate an unbound field, FieldSelecting would be the right event to handle.

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