3

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)"
}
aled
  • 21,330
  • 3
  • 27
  • 34
VKP
  • 589
  • 1
  • 8
  • 34

1 Answers1

4

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.

aled
  • 21,330
  • 3
  • 27
  • 34
  • Sorry , i am not following 100% . Would you able to make the code change to make it running . – VKP Feb 14 '21 at 20:51
  • 1
    I'm not I'm front of a computer jus a phone, I can't test it. It should be something like `---(if (cond1) address1[0 to 30] else "" ) ++ (if (cond2) ...)` – aled Feb 14 '21 at 20:55