muledataweavemule4

How to assign value to a local variable in function in DataWeave


enter image description hereHi i am getting an error saying Invalid input ' ', expected '}' for the do block. I am trying to create a concatenated String output

fun getStreetAddress(address1 ,address2) = 
do {
var addr1 = address1
var addr2 = address2
var finalAddress = ""
---
if(null != address1 and sizeOf(address1>30)) 
addr1 = address1[0 to 30]
if(null != address2 and sizeOf(address2>30)) 
addr2 = address2[0 to 30]
finalAddress = "$(addr1) $(addr2)"
}

Solution

  • You are using variables incorrectly. You can't assign a value to variable in the body of the block. Only in the definition part, before the --- separator. Remember that DataWeave is a functional language, not an imperative one.

    Try returning the result of the scores directly. You can also use if() as a function.