0
votes

We have a few needs to have a time field in Acumatica (PXDBInt as total minutes) to show the value to the user and allow the user to enter in a negative value. The standard formatting of the PXDBTimeSpanLong attribute doesn't allow a negative value to be entered or correctly displayed (db value or unbound formula value is negative already).

Has anyone created a custom class that inherits PXDBTimeSpanLongAttribute and been able to get a negative value to display and be entered? We are using the TimeSpanFormatType.ShortHoursMinutesCompact format which displays in hh:mm

Example user entries:

  • "01:30" (1 hour and 30 minutes)
  • "-02:45" (negative 2 hours and 45 minutes)
  • "00:05" (5 minutes)

Sample DAC usage for PXDBTimeSpanLongAttribute:

public abstract class myTime : PX.Data.IBqlField
{
}
[PXDBTimeSpanLong(Format = TimeSpanFormatType.ShortHoursMinutesCompact)]
[PXUIField(DisplayName = "My Time")]
public virtual Int32? MyTime { get set; }

Testing the formatting using ShortHoursMinutesCompact

  • A positive value between "00:00" (int 0) and "23:59" (int 1439) works correctly

  • A negative number while stored in the database correctly is not correctly displayed (assuming the entry allows for negative entry). For example an expected "-02:45" (int -165) value results in a display of " 0:2 ". When I click in the field then click out the value is changed to "00:02" without entering any new value.

  • There is no field restriction from entering in a value greater than 24 hours even though the intent of the ShortHoursMinutesCompact format is a 24 hour entry. The field will allow and accept any value that fits the hh:mm format (values between "00:00" and "99:99"). When the user enters for example "29:00" the displayed value is changed to "05:00" but the database value is 1740 (29 hours as total minutes).

1

1 Answers

0
votes

Found a workaround

While I need the PXDBTimeSpanLongAttribute to accept negative values for all allowable formats I was able to solve the more important issue for my requirement of needing a negative value 24 hour time field (which validates the entry within -24 to +24 hours).

I found PXTimeListAttribute is a working version of PXDBTimeSpanLongAttribute (when using the ShortHoursMinutesCompact format).

Benefits of using PXTimeList vs PXDBTimeSpanLong (ShortHoursMinutesCompact)

  • Using an int data type - no need to change the database field type. (Need to include the PXDBInt attribute with PXTimeListAttribute vs before PXDBTimeSpanLong was both)
  • Allows for both positive and negative numbers
  • Restricts the entry from within +/- 23:59

In a perfect world it would be nice to allow -24:00 to +24:00 but topic for another day.

In addition to changing the attribute used on my DAC/field I had to update the page entry for my field from a PXMaskEdit to PXTimeSpan using the following example:

Page grid - RowTemplate:

<px:PXTimeSpan ID="edMyTimeField" TimeMode="True" runat="server" DataField="MyTimeField" InputMask="hh:mm" CommitChanges="True" />

Page grid - Columns:

<px:PXGridColumn DataField="MyTimeField" Width="60px" AutoCallBack="True" RenderEditorText="True"/>

Sample usage of the attribute:

#region MyTimeField
public abstract class myTimeField : PX.Data.IBqlField
{
}
[PXDBInt]
[PXTimeList]
[PXDefault(0)]
[PXUIField(DisplayName = "My Time")]
public virtual Int32? MyTimeField { get; set; }
#endregion