I know pxformula could do it, but pxformula only accepts two argument parameters. how can i add (sum) multiple fields of the same DAC? can i nest it?
thanks. some working examples would be appreciated, some other methods would also be appreciated.
I know pxformula could do it, but pxformula only accepts two argument parameters. how can i add (sum) multiple fields of the same DAC? can i nest it?
thanks. some working examples would be appreciated, some other methods would also be appreciated.
If you do a code search on PXFormula you should find many examples. I usually search the code found in your site/App_data/CpdeRepository directory if you have access to a local site.
If you are looking to perform a multi field calculations, you nest your Add, Sub, Mult, Div, etc. calls.
Here are some examples from my search on "PXFormula" or "Mult<" or "Add<":
Found in ARTranRUTROT.CuryRUTROTTotal, this example will subtrack curyExtPrice from curyDiscAmt and add curyRUTROTTaxAmountDeductible (unless null use zero)
[PXFormula(typeof(Add<Sub<ARTran.curyExtPrice, ARTran.curyDiscAmt>,
IsNull<curyRUTROTTaxAmountDeductible, decimal0>>))]
Found in GLTaxTran.CuryExpenseAmt. This example again uses multiple fields in the calculation all nested.
[PXFormula(typeof(Mult<Mult<GLTaxTran.curyTaxableAmt,
Div<GLTaxTran.taxRate, decimal100>>, Sub<decimal1,
Div<GLTaxTran.nonDeductibleTaxRate, decimal100>>>), null)]
As suggested in another answer, PXFormula can be used to perform a multi field calculation. However, PXFormula always assigns calculated value to the field it decorates.
PXUnboundFormulaAttribute might be a better approach in case you don't need to store calculated value in any field:
[PXUnboundFormulaAttribute(typeof(Switch<Case<Where<GLTranDoc.debitAccountID, IsNotNull>, GLTranDoc.curyTranTotal>, Sub<GLTranDoc.curyTaxAmt, GLTranDoc.curyInclTaxAmt>>),
typeof(SumCalc<GLDocBatch.curyDebitTotal>))]
For additional examples on the PXUnboundFormulaAttribute, please check Example 7.3: Adding Conditional Calculation of Aggregated Values in the T200 developer class guide at Acumatica University or Acumatica Open University