Skip to main content
Solved

How to replace a formula for a field


Forum|alt.badge.img

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,

Best answer by junmao01

@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.

View original
Did this topic help you find an answer to your question?

2 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3377 replies
  • December 6, 2023

@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)
		{
		}

 

 


Forum|alt.badge.img
  • Author
  • Varsity I
  • 26 replies
  • Answer
  • December 6, 2023

@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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings