How To sum multiple fields in Acumatica (pxformula)

依然范特西╮ 提交于 2019-12-12 02:13:30

问题


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.


回答1:


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)]



回答2:


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



来源:https://stackoverflow.com/questions/42087790/how-to-sum-multiple-fields-in-acumatica-pxformula

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!