Solved

UnboundFormula problem - values out of sync

  • 3 November 2023
  • 2 replies
  • 64 views

Userlevel 4
Badge +1

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? 

icon

Best answer by RohitRattan88 3 November 2023, 17:32

View original

2 replies

Userlevel 4
Badge

My experience with those calculations is that they use an increment/decrement type of approach and once a DB value is out of band with total the only fix is a DB script one.  Perhaps you could also use the PXDatabase calls to allow you to perform updates without the DAC based logic firing.

I would love to hear that I am wrong on this, as it has been a challenge in the past.

Userlevel 7
Badge +4

@stephenward03 

I think your declaration SOLineSplit override is missing CacheAttached event:

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>))]
protected virtual void SOLineSplit_Qty_CacheAttached(PXCache sender) { }
}

 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved