You need to work with a DB-calculated formula or a helper field in your custom DAC.
1. Understand the Stock Behavior
The stock GLTran
DAC likely uses a display-only attribute or a calculated field to format YYYYMM
into MM-YYYY
for presentation. When used in a Generic Inquiry (GI), this transformation is handled seamlessly by the system.
2. Create a Display Field for FinPeriodID
You can create a calculated field in your DAC that manipulates the YYYYMM
value into the desired MM-YYYY
format.
Example Implementation:
#region FinPeriodIDFormatted [PXString(7, IsUnicode = true)] [PXUIField(DisplayName = "Fin. Period (Formatted)")] public virtual string FinPeriodIDFormatted { get { if (string.IsNullOrEmpty(this.FinPeriodID)) return null;
- The
FinPeriodIDFormatted
field is a calculated property that takes the stored FinPeriodID
(in YYYYMM
format) and reformats it to MM-YYYY
. - Use
Substring
to extract the last two digits (month) and the first four digits (year) from FinPeriodID
.
3. Add to Generic Inquiry
In Generic Inquiries, include the FinPeriodIDFormatted
field instead of the raw FinPeriodID
. This field will display the MM-YYYY
format for easy filtering and reporting.
4. If You Need a DB-Level Transformation
For database-level manipulation, you can use a SQL-calculated field by specifying the formula in your DAC using the PXDBCalced
attribute.
Example with PXDBCalced
:
#region FinPeriodIDFormatted [PXDBCalced(typeof(Substring<GLTran.finPeriodID, int4, int2> + "-" + Substring<GLTran.finPeriodID, int0, int4>), typeof(string))] [PXUIField(DisplayName = "Fin. Period (Formatted)")] public virtual string FinPeriodIDFormatted { get; set; } public abstract class finPeriodIDFormatted : PX.Data.BQL.BqlString.Field<finPeriodIDFormatted> { } #endregion
- This SQL-calculated field will dynamically generate the
MM-YYYY
format for the FinPeriodID
column at the database level.
5. Align with UI/Filtering Expectations
Ensure the field aligns with UI expectations:
- Add
[PXUIField]
to ensure the field appears correctly in forms and inquiries. - Use the formatted field in reports, screens, and GIs where users need
MM-YYYY
.
Summary
- Use a helper property or DB-calculated field to format
YYYYMM
to MM-YYYY
. - The
Substring
method allows splitting and reordering of the string. - Use the formatted field in UIs and GIs for consistent user interaction.