1

I am using Mule 4 and Anypoint Studio 7.

I am looking at renaming the file that I'm processing with the timestamp that it has been processed. So test.csv becomes test+2019-01-30T16:32:56.95Z.csv.

My issue is that it appears to work when I run the application but there is an error showing against the "Set Variable" component where I set the create filename to use by using the expression below:

#["myfolder/" ++ (payload.key splitBy("."))[0] ++ "+" ++ now() ++ "." ++ (payload.key splitBy("."))[1]]

The error message that I see on the "Set Variable" component is:

Unable to call any overload of function `splitBy` with arguments (String | Null, String) overloads:
    - splitBy(text: String, separator: String) -> Array<String> reason:     
        - Expecting Type: String, but got: Null.
        TIP: Try using `default` operator to avoid nullable objects.
        TIP: Use `!` value selector modifier to assert that an optional field is always present.
    - splitBy(text: String, regex: Regex) -> Array<String> reason:  
        - Expecting Type: String, but got: Null.
        TIP: Try using `default` operator to avoid nullable objects.
        TIP: Use `!` value selector modifier to assert that an optional field is always present.
        - Expecting Type: Regex, but got: String.

How can I resolve this error? I have tried the tips to use default but the error still shows.

Thanks

user3165854
  • 1,505
  • 8
  • 48
  • 100

1 Answers1

2

The problem here is that for some reason the metadata of your payload says that your key is optional or nullable. So data weaves type checker fails by saying that your script is going to fail what that happens. So in order to fix this you can simple do

#["myfolder/" ++ (payload.key default "." splitBy("."))[0] ++ "+" ++ now() ++ "." ++ (payload.key default "." splitBy("."))[1]]

The default operator will make sure that your value is not nullable

machaval
  • 4,969
  • 14
  • 20