Skip to main content

I have been asked if it’s possible to set the From Period to default to 01-2022 instead of 01-2023.  I’m not sure how to go about doing this.  I presume I need to somehow get the correct Period ID from the string 01-2022 or date 01/01/2022 and set it in the FieldDefaulting Event Handler but I’m not sure how to go about getting the PeriodID to set.

Thanks for any advice,

Phil

One way to do this is by using the FieldDefaulting event handler for the From Period field.

Here are the steps you can follow to set the default value for the From Period field:

  1. Create a custom field defaulting event for the From Period field in your customization project.
  2. In the event handler, use the PXSelector attribute to query the FinancialPeriod DAC for the period with the start date of 01/01/2022.
  3. Use the PXCache.SetDefault() method to set the value of the From Period field to the Period ID of the period you retrieved in step 2.

Here is an example of what the code for the custom field defaulting event might look like:

[PXDBString(6, IsKey = true, InputMask = "yyyyMM")]
[PXDefault(typeof(Search<FinPeriod.finPeriodID, Where<FinPeriod.startDate, Equal<Required<FinPeriod.startDate>>>>))]
protected virtual void FinPeriod_FromPeriodID_CacheAttached(PXCache sender)
{
}

In this case, the default value for the From Period field will be set to the finPeriodID for the FinPeriod with the start date 01/01/2022.

Note that you will also need to make sure that the Financial Periods for 2022 have already been created in the system before this customization is applied.


@Yuriy Zaletskyy Thanks very much for taking the time to give such a detailed answer.  I really appreciate it.

 

Phil


Reply