0
votes

I am getting a field AnnualRevenue in the input, I have to look for the condition that if there is a decimal in that field I want to substing it to a whole number, but if it does not a decimal, it is passed without any transformation. Can one tell me how this could be achived in dataweave in mulesoft.

4

4 Answers

0
votes

For another alternative, You can utilize regex:

%dw 1.0
%output application/java
---
{
    result: "123.45" replace /(\.[0-9]*)/ with ""
}
0
votes

Aside from subtring you can use the integer conversion of MEL/java by creating a global MEL function then use it in your dataweave expression.

<configuration doc:name="Configuration">
    <expression-language>
        <global-functions>
            def removeDecimal(value) {
            return (long) value
            }
        </global-functions>
    </expression-language>
</configuration>

then in your dataweave expression:

%dw 1.0
%output application/json
---
{
    "result": removeDecimal(-21.83)
}

Hope it helps.

Cheers

0
votes
input:

<employees>
  <employee>
  <name>salumiah-syed</name>
  </employee>
</employees>

%dw 1.0
%output application/xml 
---
result: (payload.employees.employee.name splitBy "-") [0] 
0
votes

Or

%dw 1.0
%output application/java
---
{
     value: "123.45",    
     result: ("123.45" as :number) as :string {format: "#"}
}

Reference: https://docs.mulesoft.com/mule-runtime/3.9/dataweave-operators#coerce-to-string