PXUnboundDefault特性失效,迁移查询后无SQL执行记录求助
Let's break down why your UsrLastCost field's PXUnboundDefault attribute isn't triggering the expected SQL query, especially since the same logic worked in an event handler. I've dealt with similar Acumatica attribute quirks before, so here are targeted checks and fixes:
1. Verify the Context of Current<SOLine.inventoryID>
The Current operator in your query relies on the active cache context for SOLine, but DAC extension fields sometimes have subtle context differences compared to core DAC fields. Try adjusting the query to use Parent instead, which explicitly ties to the parent SOLine row:
[PXUnboundDefault(typeof(Search<INItemStats.lastCost, Where<INItemStats.inventoryID, Equal<Parent<SOLine.inventoryID>>>>))] [PXDecimal] [PXUIField(DisplayName = "Last Cost", Enabled = false, Visible = true, IsReadOnly = true)] public virtual Decimal? UsrLastCost { get; set; }
Also, confirm the SOLine.InventoryID field is populated before the default value tries to load—if it's null, the query will not execute at all.
2. Check PXUnboundDefault Execution Timing
PXUnboundDefault only runs in specific scenarios:
- When a new
SOLinerow is first initialized - When the dependent field (
InventoryID) is updated on an existing row
If you're editing an existing row where InventoryID was already set, the default won't re-trigger automatically. You can test this by creating a new sales order line, or manually force a refresh of the field in the InventoryID FieldUpdated event as a fallback:
public void SOLine_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e) { var line = e.Row as SOLine; if (line?.InventoryID == null) return; var stats = PXSelect<INItemStats, Where<INItemStats.inventoryID, Equal<Required<INItemStats.inventoryID>>>>.Select(Base, line.InventoryID); var ext = cache.GetExtension<SOLineExt>(line); ext.UsrLastCost = stats?.LastCost; }
3. Confirm Extension and Field Registration
- Double-check that your
SOLineExtDAC extension is properly registered in your customization project (via the Customization Project Editor). If it's not registered, the field won't be recognized by the system at all. - Ensure the
UsrLastCostfield is added to the SOLine grid/form in the page layout. Acumatica often skips initializing fields that aren't visible in the UI, even if you setVisible = truein the attribute.
4. Rule Out Permissions and Data Issues
- Check if the current user has read access to the
INItemStatstable. Event handlers sometimes run with elevated permissions, while attribute-based queries use the current user's permissions—missing access could suppress the SQL execution. - Run the raw SQL equivalent directly against your database to confirm data exists for a test
InventoryID:SELECT LastCost FROM INItemStats WHERE InventoryID = [your-test-inventory-id]
5. Compare to Your Working Query
Cross-reference the working query from your other customization to spot differences:
- Is the working query tied to a core DAC field instead of an extension?
- Does it use a different context operator (like
Currentvs.Required)? - Is the dependent field in the working scenario marked as required, ensuring it's always populated before the default runs?
If none of these fixes work, enable Acumatica's Trace Logging (under System > Management > Trace) to check for hidden errors related to field initialization or query execution.
内容的提问来源于stack exchange,提问作者Rob

