Search code examples
dataweaveanypoint-studiomulesoft

Type mismatch error in splitting a payload in mule3


I am creating variable which is an array in a transform (dw1). Then I am using for each to process each element of this array. Within for each another transform is being used which contains:

%var lineName = payload.split("-")[0]

But I am getting a type mismatch error for value selector. Please refer to image for error. Thanks in advance.enter image description here


Solution

  • You are using incorrectly the operator. Note that DataWeave is not Java. DataWeave is a different language. You should not try to use Java methods nor syntax. Please read the documentation to learn more about DataWeave 1.0: https://docs.mulesoft.com/dataweave/1.2/

    The right way to write this would be:

    %dw 1.0
    %output application/json
    ---
    payload[0] splitBy "-" 
    

    I'm not sure if this will work as is because I don't have your input data nor expected output, but from a syntax perspective this is correct. You can use the same expression inside the variable definition.