Hello,
I’m trying to use UnBoundFormula to aggregate some values in a detail DAC and save the result to a custom field in a header DAC.
Below is my extension to the qty field on the SOLineSplit DAC. I want get the sum of allocated lines, and write this to usrQtyAllocated on SOLineExt.
public class SO_SOLineSplit_ExistingColumn : PXCacheExtension<PX.Objects.SO.SOLineSplit>
{
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXUnboundFormula(
typeof(Switch<Case<Where<SOLineSplit.isAllocated, Equal<True>>, SOLineSplit.qty>, decimal0>),
typeof(SumCalc<SOLineExt.usrQtyAllocated>))]
public Decimal? Qty { get; set; }
}
Below is the definition of the custom field on SOLine where I want to write the total.
public class SOLineExt : PXCacheExtension<PX.Objects.SO.SOLine>
{
[PXDBQuantity()]
[PXUIField(DisplayName = "Qty Allocated", IsReadOnly = true)]
[PXDefault(TypeCode.Decimal, "0.0")]
public virtual Decimal? UsrQtyAllocated { get; set; }
public abstract class usrQtyAllocated : PX.Data.BQL.BqlDecimal.Field<usrQtyAllocated> { }
}
This set up works, the total is calculated and ‘affects’ the parent field. But not quite in the way I expected.
From everything I’ve read it sounded like that UsrQtyAllocated would be set to the calculation result, however, in my testing, I can see that the calculation result is added to the value in UsrQtyAllocated!
Below is a screen shot showing the relevant part of a sales order. The Qty Allocated field is my custom field. All values have been reset to 0.

I enter quantities for each item, this sales order is set to allocate stock during order entry, so the SOLineSplit tables are updated, then my PXUnboundFormula fires and writes the result back to the Qty Allocated field. The 3rd line only has 2 in stock, so this appears to be working well.

In the process of developing my solution, unpublishing and publishing the customisation, the value in Qty Allocated has become unsynchronised with the sum of the detail lines. I’ve simulated this in the screenshot below.

My hope was that changing the Quantity value would perform the calculation and reset the Qty Allocated value. But instead the calculation is added to the current value.

Does anyone know of a way to reset the value of the target field when using PXUnboundFormula?