Skip to main content

How to declare a variable and instantiate Arraylist & HashMap object to it in dataweave 2 (i tried using java:invoke its working but is there a way to declare in dataweave ?). i should use this var to accumulate objects in a for loop and use it later .

3 answers
  1. Aug 4, 2021, 8:49 AM

    @Ganesh Palani​ 

     

    What is the need of creating a Java object reference directly?

     

    If you just wants to accumulate the payloads from for loop, you can create an object a variable outside the for scope and append the values in for scope and use it later on.

     

    @Ganesh Palani​ What is the need of creating a Java object reference directly?Attaching example flow:

    <flow name="testFlow1" doc:id="73a70eb2-9d8e-46b1-be71-694620e8f115" >

    <set-variable value="#[[]]" doc:name="myVar" doc:id="91444a89-bb1e-4287-b628-59e740a8b98c" variableName="myVar"/>

    <foreach doc:name="For Each (1 to 10)" doc:id="1b420d4f-0bf3-4c15-937a-b852016e0f33" collection="#[1 to 10]">

    <set-variable value="#[vars.myVar + payload]" doc:name="myVar" doc:id="7f24b408-afc8-4b44-95c7-e38ff2a438ae" variableName="myVar" />

    </foreach>

    <logger level="INFO" doc:name="Log myVar" doc:id="c762d992-6f79-4391-a410-354419bd11a1" message="#[output application/json --- vars.myVars]"/>

    </flow>

    Regards,

    Chetan

0/9000