I have a DateTime field that contains the MM/DD/YYYY HH:MM:SS date/time in the database, but when I apply it to a PXGrid, it only displays the date. How can I make it display the date AND TIME? I'm overriding the DAC object with the following attributes:
[PXUIField(DisplayName = "Start Time", Visibility = PXUIVisibility.SelectorVisible)]
[PXDBDateAndTime()]
[PXDefault]
protected virtual void FSAppointment_ScheduledDateTimeBegin_CacheAttached(PXCache Sender) { }
Try to add attribute [PXDBDate(PreserveTime = true)] instead of [PXDBDateAndTime()]
A year later, I stumbled onto this because I had the same question. Here's what worked for me.
[PXDBDate(DisplayMask="f",PreserveTime=true,InputMask="f")]
Related
I have a formula I am using the calculate a non-persisting field. I'm redefining a base DAC field: POVendorItem.VLeadTime. This is my new definition:
#region VLeadTime
[PXShort(MinValue = 0, MaxValue = 100000)]
[PXUIField(DisplayName = "Vendor Lead Time (Days)", Enabled = false)]
[PXFormula(typeof(Sub<Current<usrCFAvgLeadTime>, Current<POVendorInventory.addLeadTimeDays>>))]
public virtual short? VLeadTime { get; set; }
#endregionv
Both fields in the formula are defined as PXDBShorts, yet I keep getting a "Specified cast is not valid" error when trying to access the grid the field is on. Here is the trace:
I've also noticed that if I type out a statement such as short? = short? - short? I also get an error in VS stating I can't convert an int? to a short? which doesn't make sense. For me to correctly calculate it, VS auto corrects the formula to short? = (short?)((short)(short?) - (short)(short?)) adding in a ton of type casts.
To get around the formula, I would attach events to field defaulting for VLeadTime, as well as field updating for usrCFAvgLeadTime and addLeadTimeDays and then recalculate it and set the value. I know it is redundant, but as long as you can set the value to a short in visual studio in the code, it would set for VLeadTime.
This is what I've tried with the addition of so many variations using FBQL.
[PXDBDate]
[PXDefault(typeof(SelectFrom<ARInvoice.docDate>.
AggregateTo.Max<ARInvoice.docDate>.GroupBy<BAccount.acctCD>>))]
[PXUIField(DisplayName="Last Invoice Date", Visibility = PXUIVisibility.SelectorVisible)]
I think the problem I'm having is how to select a date type with one value.
Maybe somthing like this?
[PXDBDate]
////[PXDefault(typeof(SelectFrom<ARInvoice.docDate>.
////AggregateTo.Max<ARInvoice.docDate>.GroupBy<BAccount.acctCD>>))]
[PXDefault(typeof(Select<ARInvoice, OrderBy<Desc<ARInvoice.docDate>>>))]
[PXUIField(DisplayName = "Last Invoice Date", Visibility = PXUIVisibility.SelectorVisible)]
I've added the Excel upload feature to the Details section of the Employee Time Card screen (EP305000). This works fine, but if the 'Time' field (which is actually date_time, but I can't find that in the DAC - only 'Date') isn't specified in the upload, it defaults to midnight (12:00 AM). I want this to default to 8:00 AM, but I'm not sure how to do this, since the field is actually a date. It doesn't seem like I can just use [PXDefault] or anything simple like that.
How can I accomplish this?
Thanks...
Here's the solution I came up with, using the 'RowInserted' event:
protected void EPTimeCardDetail_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
{
var eptcd = (EPTimecardDetail)e.Row;
DateTime theDate = (DateTime)eptcd.Date;
DateTime MyDate = new DateTime(theDate.Year, theDate.Month, theDate.Day, 8, 0, 0);
eptcd.Date = MyDate;
}
I am writing an override for CalculateSalesPriceInt() (The function that calculates the sale price for an item) Here is the code in question
[PXOverride]
public virtual decimal? CalculateSalesPriceInt(PXCache sender, string custPriceClass, int? customerID, int? inventoryID, int? siteID, CurrencyInfo currencyinfo, decimal? quantity, string UOM, DateTime date, bool alwaysFromBaseCurrency,
Func<PXCache, string, int?, int?, int?, CurrencyInfo, decimal?, string, DateTime, bool, decimal?> del)
{
Customer cust =
PXSelect<Customer, Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>.Select(
Base, customerID);
InventoryItem item =
PXSelect<InventoryItem,
Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>
.Select(Base, inventoryID);
var itemExt = item.GetExtension<Arctc001InventoryItem>();
var custExt = cust.GetExtension<Arctc001Customer>();
The issue is with the InventoryItem and Customer selects. The process is such:
Create new sales order for a customer
Insert Item A into SOLines
Decide I dont like the Descr(or any other field) for item A and click on the hyperlink to pop open an instance of the StockItemMaint Page
Edit the Descr Field so it is different
Press Save and close the StockItemMaint page
Delete said InventoryItem from SOLines
Re-Add the same InventoryItem back in
Calculate SalesPriceInt fires off as I add the item back in
In debug mode, take a look at the results of PXSelect and even though I have Persisted my changes in the window, the old values still come up.
I have tried using either PXSelect or PXSelectReadonly, and no matter what the old values before I changed the inventoryitem record still come back as a result
How can I work with the cache so I get these persisted values?
Thanks
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.