Mule Dataweave: Need to extract values from an array -
added new code, trying first save linedata, processing header , coming line, not liking setpayloadtolines
<set-variable variablename="linedata" value="#[payload.lineid]" doc:name="variable"/> … <set-payload value="linedata" doc:name="setpayloadtolines" /> <foreach doc:name="for each" collection="#[payload.lineid]"> <db:insert config-ref="oracle_configuration" doc:name="database"> <db:parameterized-query><![cdata[insert hdr_table (line_id,id) values(line_seq.nextval,#[payload.lineid])]]></db:parameterized-query> </db:insert> </foreach>
since ou haven't shown full json request, let's consider have following json:-
{ "industry": ["111","ggh","ooo",888], "phone": null, "id": null, "type": "account", "name": "manufacturing" }
so here how ou can extract each comma separate value , insert db:-
<http:listener-config name="http_listener_configuration" host="0.0.0.0" port="8081" doc:name="http listener configuration"/> <flow name="testflow" > <http:listener config-ref="http_listener_configuration" path="/test" doc:name="http"/> <json:json-to-object-transformer returnclass="java.lang.object" doc:name="json object"/> <logger level="info" doc:name="logger" message="#[payload.industry]"/> <foreach doc:name="for each" collection="#[payload.industry]"> <logger message="each extracted value :#[payload]" level="info" doc:name="logger"/> <!-- database insert code here inserting each value #[payload] --> </foreach> <json:object-to-json-transformer doc:name="object json"/> </flow>
you can modify above code , use insert db.
pls note inside loop #[payload]
has extracted comma separated value. can put variable if want , use instead of writting #[payload]
update:
as per question, have updated query:-
<foreach doc:name="for each" collection="#[payload.lineid]"> <db:insert config-ref="oracle_configuration" doc:name="database"> <db:parameterized-query><![cdata[insert hdr_table (id,line_id) values(line_seq.nextval,#[payload])]]></db:parameterized-query> </db:insert>
Comments
Post a Comment