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).
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
Related
In the image below, the three fields in the first red square are the ones that I want a calculated value to be. For example, Actual Income would hold the sum of the two columns at the bottom with the red square (I'm not trying to necessarily grab those two fields for the sum, but they just serve as an example).
So what I'm wondering is how would I go about summing up all the values within those two columns and adding the result to one of the three fields (e.g. Actual Income)?
Any help on this issue would be greatly appreciated :D
The image below shows the details for the column 'Original Budgeted Amount'
The image below shows the details for the field 'Actual Income'
#WARNING# After a review of the base code it appears those three header fields are used in the calculation of accumulative table ( financial history ) PMTaskTotal as such I would highly suggest not modifying values.
As an alternative :
One method is to add another field to the child record to hold the summary amount of the two fields wanted, I would then add an additional field to the header to hold the calculated value.
Child record field:
#region CuryAmount
/// <summary>
/// The amount that is a summary of your two fields
/// </summary>
public abstract class curyAmount : BqlDecimal.Field<curyAmount>
{
}
[PXDefault(TypeCode.Decimal, "0.0")]
[PXFormula(typeof(Sum<field1, field2>))] //Calculates sum of fields
[PXUIField(DisplayName = "Summary Field", Required = true)]
[PXUnboundFormula(typeof(curyAmount), typeof(SumCalc<Header.sumfield>))] //Assigns values to header field
public virtual decimal? CuryAmount { get; set; }
#endregion
Parent record field :
#region CuryTotalAmount
/// <summary>
/// The total amount in the from the summed childrecords.
/// </summary>
public abstract class curyTotalAmount : BqlDecimal.Field<curyTotalAmount>
{
}
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Total Amount", Enabled = false)]
public virtual decimal? CuryTotalAmount { get; set; }
#endregion
The field in the DAC is defined like this.
#region NextMonthHours
[PXDBDecimal(2, MinValue = 0.0, MaxValue = 280.0)]
[PXUIField(DisplayName = "Next Month Hours")]
[PXDefault(TypeCode.Decimal, "0.0")]
public virtual Decimal? NextMonthHours { get; set; }
public abstract class nextMonthHours : PX.Data.BQL.BqlDecimal.Field<nextMonthHours> { }
#endregion
I change the display name of the field in RowSelected event.
PXUIFieldAttribute.SetDisplayName<EVEPPlannedHoursDetails.nextMonthHours>(sender, nextMonth+"Hours");
where nextMonth is "February".
I need to add this field to Acumatica Mobile Screen. When I go to web service schema the field name is "FebruaryHours"
<s:element minOccurs="0" maxOccurs="1" name="FebruaryHours" type="tns:Field"/>
I cannot use the name "FebruaryHours" because it changes every month but I also when I use field name NextMonthHours it is not added in the mobile screen.
Any idea how to solve this issue?
Thanks
There's quite a few ways to workaround this depending on the use case and whether the label value is static or dynamic.
If all you want to do is to change a static label in UI without having to change the display name property you can add a separate label and merge group.
Here's an example to change Billable in UI without changing DisplayName property using that technique.
Set SuppressLabel property to true to hide the original label bounded to DisplayName on UI.
Use ADD CONTROLS tab to add a Layout Rule with Merge property set to true.
Use ADD CONTROLS tab to add a label control in the merged group.
Put the original field in the merge group so they show up together on the same line in UI.
End result, label is now a UI control and wouldn't interfere with DisplayName property.
I am trying to make a field required on the line item of an AP Invoice, the Tax Category field. However when I change the field to be required I run into the problem of the detail total and the balance to no longer update on the form.
What I've tried doing is eliminating the PersistingCheck = PXPersistingCheck.Nothing of the PXDefault attribute of the TaxCategoryID. This causes the field to be required on the form, however as I've stated, it also causes the form to no longer update totals. I've tried changing the PersistingCheck to PXPersistingCheck.Null, but this also prevents the totals from being updated.
Originally the PXDefault attribute for the Tax Category field is as follows:
[PXDefault(typeof(Search<InventoryItem.taxCategoryID,
Where<InventoryItem.inventoryID, Equal<Current<APTran.inventoryID>>>>),
PersistingCheck = PXPersistingCheck.Nothing)]
This is what my code is:
[PXDefault(typeof(Search<InventoryItem.taxCategoryID,
Where<InventoryItem.inventoryID, Equal<Current<APTran.inventoryID>>>>))]
What I want is to be able to have the Tax Category field required and the totals to be updated as usual, but I am not able to due to something in the code preventing the totals to be updated when the PXDefault attribute of the Tax Category field is changed.
Is there anything additional I must do in order for these issues to be resolved or am possibly going about this the wrong way?
You need to correctly change the PersistenceCheck and add Required=true to PXUIFieldAttribute for showing a red asterisk symbol near the column's name. Please see the example of how to do that using PXMergeAttributesAttribute and PXCustomizeBaseAttribute:
public class APInvoiceEntry_Extension : PXGraphExtension<APInvoiceEntry>
{
#region Event Handlers
[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXCustomizeBaseAttribute(typeof(PXUIFieldAttribute), nameof(PXUIFieldAttribute.Required),true)]
[PXCustomizeBaseAttribute(typeof(PXDefaultAttribute), nameof(PXDefaultAttribute.PersistingCheck), null)]
protected virtual void APTran_TaxCategoryID_CacheAttached(PXCache cache)
{
}
#endregion
}
I have a User Defined Table that I link to the BAccount table in Acumatica. What I'm trying to do is use the PXDBCreatedDateTime attribute to save the CreateDateTime when the UDFs are set. Is this posssible? It doesn't seem to work right now.
[PXTable(typeof(BAccount.bAccountID),IsOptional=true)]
public class CustomerExtension : PXCacheExtension<BAccount>
{
[PXDBCreatedDateTime()]
[PXUIField(DisplayName = "Date")]
public DateTime? CreatedDateTime { get; set; }
public class createdDateTime : IBqlField { }
}
I would assume it would not work as the BAccount table already contains a field with the same name 'CreatedDateTime'. I would first use a different field name for table extension fields as this could create some conflicts to those fields that already exist with the same name. Also, extension tables are inserted when the base table is either inserted or updated (first time after extension table is added) which may or may not occur from changes to your extension fields. This would also cause some issues for getting a good date from your PXDBCreatedDateTime field. You might be better off using a standard date time field and use some type of formula to update the date when your fields change. I would have to research the formula. You could use logic inside the setter of your user fields and add the PXDependsOnFields attribute to your date field and set your date field if null. I have not tried PXDependsOnFields in an extension - but the logic could be promising.
does anyone know how to change the decimal places displayed for a custom calculated field? Right now it is displaying 12 decimal places, and I only want it to display 2.
Also, I am trying to bold the font of a custom field on a screen. Any idea how to do that?
The number of decimal places can be defined in you PXDBDecimal/PXDecimal attribute of your custom field
Eg:
[PXDBDecimal(2)] // 2 decimal places
[PXDefault(TypeCode.Decimal, "0.00")]
[PXUIField(DisplayName = "Quantity", IsReadOnly = true)]
public Decimal? PQty { get; set; }
For the Bold font, i dont know any attributes available. May be you should try customizing your ASPX or there are many advanced properties like CSSClass available in the customization project > screen > control > properties.