0

I am adding the elements of a payload in Dataweave 1.0 as below :

%var summation =[[]]

summation :sum ((schemaInput map ($.BenefitLimit when $.BenefitLimit !="" otherwise (0 as :number)))) ,

Can anyone help me to replicate the same logic in Dataweave 2.0 ??

Thanks

Sourabh
  • 1
  • 1

1 Answers1

0

Here is a rough conversion without knowing the context.

A few points on the changes:

  1. dw 2.0 header

  2. fun or var instead of %var - no need for %

  3. when/otherwise in dw 2 is now if/else

  4. use sum instead of :sum - no need for : anymore with operators and functions

    %dw 2.0

    output application/java

    var data= [ {"BenefitLimit": "10"}, {"BenefitLimit": "20"}]

    fun summation(schemaInput) = sum ((schemaInput map ((if ($.BenefitLimit == "") 0 else $.BenefitLimit as Number))))

enter image description here Documentation on migration here: https://docs.mulesoft.com/mule-runtime/4.1/migration-dataweave

Ryan Carter
  • 11,441
  • 2
  • 20
  • 27
  • Hi , The problem is that if the benefitLimit is ="" (blank) in that case summation throws error.how to resolve it – Sourabh Jan 21 '19 at 13:51