Solved

How to replace a formula for a field

  • 6 December 2023
  • 2 replies
  • 57 views

Userlevel 2
Badge

The Purchase Order “Line Total” field is the summary of lines curyExtCost filed which is defined in the POTaxAttribute: PXUnboundFormulaAttribute(typeof(POLine.curyExtCost), typeof(SumCalc<POOrder.curyLineTotal>)).

I want to add a condition to the formula to exclude the Cancelled line: PXUnboundFormula(typeof(IIf<Where<POLine.cancelled, Equal<True>>, decimal0, POLine.curyExtCost>), typeof(SumCalc<POOrder.curyLineTotal>)).

How can I replace the original PXUnboundFormula with the new one, or can I Remove the old formula and add new formula?

 

Thanks,

icon

Best answer by junmao01 6 December 2023, 23:48

View original

2 replies

Userlevel 7
Badge +17

@junmao01  Yes, we can remove the old formula and add new formula using Cache Attached event like below. 

[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXRemoveBaseAttribute(typeof( PXUnboundFormulaAttribute))] // This code will remove the base formula
//Below you can add the new formula according to your requirement
[PXUnboundFormula(typeof(IIf<Where<POLine.cancelled, Equal<True>>, decimal0, POLine.curyExtCost>), typeof(SumCalc<POOrder.curyLineTotal>))]
protected virtual void POOrder_FieldName_CacheAttached(PXCache sender)
{
}

 

 

Userlevel 2
Badge

@Naveen Boga Thanks for your reply. I tested PXRemoveBaseAttribute in the field. But the PXUnboundFormula is defined in the POTAX attribute. The PXRemoveBaseAttribute in the field doesn’t work. I end with inherit the POTAXAttribute, and clear the base attribute and define a new one.

public class POTaxCBIZAttribute : POTaxAttribute
    {
        public POTaxCBIZAttribute(Type ParentType, Type TaxType, Type TaxSumType)
            : base(ParentType, TaxType, TaxSumType)
        {
            base._Attributes.Clear();
            this._Attributes.Add(new PXUnboundFormulaAttribute(typeof(IIf<Where<POLine.cancelled, Equal<True>>, decimal0, POLine.curyExtCost>), typeof(SumCalc<POOrder.curyLineTotal>)));

        }

    }

 

Thanks.

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