Skip to main content
Solved

Set default value by event FieldDefaulting does not work


Forum|alt.badge.img

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.

Best answer by Patrick Chen

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)
View original
Did this topic help you find an answer to your question?

3 replies

Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 85 replies
  • March 31, 2023

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.


Patrick Chen
Varsity I
Forum|alt.badge.img+2
  • Varsity I
  • 51 replies
  • Answer
  • March 31, 2023

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)

Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 85 replies
  • April 1, 2023

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

It works perfectly.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings