0

I need a dataweave function which extract fix string to convert it into ISO Date String format

fun convertToISO(dateString: String): String =
    if (dateString == null) 
        "" 
    else 
        try 
            ((dateString[6 to -3] as Number) as DateTime {unit: "milliseconds"} as String)
        catch (e) 
            "WRONG FORMAT"

but I also get error says , does anyone have idea how to solve this problem?

Invalid input '"', expected ? (line 8, column 13):


8|             "WRONG FORMAT"
               ^
Location:
main (line: 8, column:13)

1 Answer 1

1

You seem to be trying to use Java try-catch syntax however DataWeave is a different language and doesn't have that syntax.

As an alternative you could use the try() and orElse() functions from the Runtime module.

%dw 2.0
output application/json
import try, orElse from dw::Runtime

fun convertToISO(dateString: String): String =
        try ( () ->
                ((dateString[6 to -3] as Number) as DateTime {unit: "milliseconds"} as String))
        orElse
            "WRONG FORMAT"
---
convertToISO("123")

Output:

"WRONG FORMAT"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.