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:
- Create a custom field defaulting event for the From Period field in your customization project.
- In the event handler, use the PXSelector attribute to query the FinancialPeriod DAC for the period with the start date of 01/01/2022.
- 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