0

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:

enter image description here

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.

EricP.
  • 489
  • 3
  • 21

1 Answers1

0

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.

KRichardson
  • 990
  • 7
  • 12