0
votes

Added new code, where I am trying to first save the lineData, processing header and coming back to line, however it is not liking the 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 INTO HDR_TABLE (LINE_ID,ID) VALUES(LINE_SEQ.NEXTVAL,#[payload.LineID])]]></db:parameterized-query>
    </db:insert>
    </foreach>

1
Do you want each comma separated value to be an input in DB?Anirban Sen Chowdhary
Yes that is true .. I want to insert as a seperate row into DB table.insaneyogi
Is dataweave required? I can show you an easy wayAnirban Sen Chowdhary
I am ok with getting rid of dataweave. by the way the complete payload looks like this .. {id=A0YAAW, LineID=[9Ej6EAE, 9EjGEAU, 9EjBEAU], name=Test 2.24, startDate=2017-02-17, ...}insaneyogi
The Line ID I want to put in one table & remaining values in anotherinsaneyogi

1 Answers

0
votes

Since ou haven't shown your full json request, let's consider you have following json:-

{
    "Industry": ["111","ggh","ooo",888],
    "Phone": null,
    "Id": null,
    "type": "Account",
    "Name": "Manufacturing"
}

So here is how ou can extract each comma separate value and insert it into 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 to 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"/>
            <!-- Your Database insert code here inserting each value with #[payload] -->
        </foreach>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
   </flow>

You can modify this above code and use it to insert into db.
pls note inside for loop #[payload] has extracted comma separated value. You can put it into a variable if you want and use it instead of writting #[payload]

UPDATE:

As per you question, I have updated your query:-

<foreach doc:name="For Each" collection="#[payload.LineID]">
    <db:insert config-ref="Oracle_Configuration" doc:name="Database">
        <db:parameterized-query><![CDATA[INSERT INTO HDR_TABLE (ID,LINE_ID) VALUES(LINE_SEQ.NEXTVAL,#[payload])]]></db:parameterized-query>
    </db:insert>