Solved

Set default value by event FieldDefaulting does not work

  • 31 March 2023
  • 3 replies
  • 368 views

Userlevel 3
Badge

Hello experts,

There is a field Promised On (Expected Date) on Purchase Orders screen (PO301000) and it is set to Today by default

I am trying to set default value of this field null and I have used the following approach:

  • Set default value to null in event handler FieldDefaulting:
using PX.Data;

namespace PX.Objects.PO
{

public class POOrderEntry_Extension : PXGraphExtension<POOrderEntry>
{
#region Event Handlers
protected void POOrder_ExpectedDate_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
var row = (POOrder)e.Row;
if (row != null)
{
e.NewValue = null;
e.Cancel = true; // If I don't use e.Cancel = true, it still doesn't work
}
}

#endregion
}
}
  • override Initialize method:
public class POOrderEntryExt : PXGraphExtension<POOrderEntry>
{
public override void Initialize()
{
base.Initialize();
PXUIFieldAttribute.SetVisible<POOrder.expectedDate>(Base.Document.Cache, null, false);
PXDefaultAttribute.SetPersistingCheck<POOrder.expectedDate>(Base.Document.Cache, null, PXPersistingCheck.Nothing);
PXDefaultAttribute.SetDefault<POOrder.expectedDate>(Base.Document.Cache, null);
}
}

but none of these solution could work. The value of field ExpectedDate is still set to Today.

Do you know is it possible to set default value of field ExpectedDate to null?

 

Thanks you for your help.

icon

Best answer by Patrick Chen 31 March 2023, 19:23

View original

3 replies

Userlevel 3
Badge

The main goal is: forcing user must add value for this field but it is set to today by default so I can’t use required = true in configuration of field in screen.

Userlevel 4
Badge +2

Try changing your code to override the event handler

protected void POOrder_ExpectedDate_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)

should be

protected void POOrder_ExpectedDate_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e, PXFieldDefaulting baseMethod)
Userlevel 3
Badge

Hello @Patrick Chen thank you very much for your answer.

It works perfectly.

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