Nickolas Hook
Nickolas Hook

Reputation: 804

Change Filter Default Value / Prevent Base graph _FieldDefaulting handler

Is there any way to change the default value of the Start Date for the "Inventory Transaction History" inquiry specifically. Viewing the base inquiry graph it sets the default using an event handler...

    protected virtual void InventoryTranHistEnqFilter_StartDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
    {
        if (true)
        {
            DateTime businessDate = (DateTime)this.Accessinfo.BusinessDate;
            e.NewValue = new DateTime(businessDate.Year, businessDate.Month, 01);
            e.Cancel = true;
        }
    }

Writing a graph extension, implementing the same event and setting the e.NewValue appears to occur before the base graph's handler so our set value is not defaulted in the filter.

using System;
using PX.Data;

namespace PX.Objects.IN
{
    public class InventoryTranHistEnq_Extension : PXGraphExtension<InventoryTranHistEnq>
    {
        #region Event Handlers

        protected virtual void InventoryTranHistEnqFilter_StartDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            DateTime businessDate = (DateTime)this.Base.Accessinfo.BusinessDate;
            e.NewValue = new DateTime(businessDate.Year - 1, businessDate.Month, 01);
            e.Cancel = true;
        }

        #endregion
    }
}

Upvotes: 0

Views: 133

Answers (1)

DChhapgar
DChhapgar

Reputation: 2340

You need to define an event handler with an additional parameter as below. In such case, framework would call event handler with link to the event handler from the extension of the previous level, if such an event handler exists, or to the first item in the event handler collection. And in your graph extension you can implement base logic to be executed before or after extension code. In your case, you would skip calling previous level.

public class InventoryTranHistEnq_Extension : PXGraphExtension<InventoryTranHistEnq>
{
    protected virtual void InventoryTranHistEnqFilter_StartDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e, PXFieldDefaulting BaseInvoke)
    {
        //If you want to execute code of base Graph or of previous level Graph extension
        //if (BaseInvoke != null) { BaseInvoke(sender, e); }

        //Your code
        DateTime businessDate = (DateTime)this.Base.Accessinfo.BusinessDate;
        e.NewValue = new DateTime(businessDate.Year - 1, businessDate.Month, 01);
        e.Cancel = true;
    }
}

You can refer Adding or Altering BLC Event Handlers Help article.

Upvotes: 1

Related Questions