Search code examples
muledataweaveanypoint-studio

How to refer payload which is a ResultSet Iterator in mule dataweave?


Sql query returns a streamed output as Resultset iterator object from the Database component. i want to convert this to xml in dataweave. But don't know how to refer the incoming object, If it's a map i can access it simply by using .operator like payload.student

Tried using payload.next() but it gives an error. Also tried the following, %var input1 payload as :iterator but still wont' work


Solution

  • Here the steps:

    • Drag and drop the Transform Message (Dataweave) component after your configured DB Connector. You will see that the input payload for dataweave script is filled with the db result List<Map>.

    • Then you can access the fields, using the map function in dw.

    dw script

    %dw 1.0
    %output application/xml
    ---
    {
        "Results":{
            (payload map {
                "key1":$."db_field1",
                "key2":$."db_field2"
            })
        }
    
    }