user3165854
user3165854

Reputation: 1655

How do you add multiple input parameters to database connector in Mule

I am using Anypoint Studio 7.3 and Mule 4.1.

I am using the database bulk insert connector and I would like to pass in multiple input parameters into the SQL insert.

I have added multiple input parameters using the following syntax

{payload: payload, tableName: vars.tblName, username: vars.username}

but I get the error below and also not sure how I should reference the values in the payload is is still :Code or payload.Code:

Cannot coerce Object ({payload: [{Code: "1",Name: "test1",Co...) to Array

The configuration I am using is:

        <db:bulk-insert doc:name="Bulk Insert" doc:id="36328b21-ffd9-485e-8afa-34b6cb742956" config-ref="db-config">
            <db:bulk-input-parameters ><![CDATA[#[{payload: payload, tableName: vars.tblName, Username: vars.username}]]]></db:bulk-input-parameters>
            <db:sql >#["INSERT INTO :tableName
(
    :tableName,
    Code,
    Name,
    Comments
    User
)
VALUES 
(
    NEWID(), 
    :Code, 
    :Name, 
    :Comments,
    :username
)"]</db:sql>
        </db:bulk-insert>

Thanks for any help

Upvotes: 0

Views: 2126

Answers (1)

machaval
machaval

Reputation: 5059

The problem here is that de bulk insert in mule expects and array of objects. Where each element of the Array is an Object with the parameters of the row to insert.

So in your case I assume payload has an array of all the Code, Names and Comments so I would use this script

<db:bulk-input-parameters ><![CDATA[#[
        payload map ((item) -> item ++ {tableName: vars.tblName, username: vars.username} )
]]]></db:bulk-input-parameters>

Upvotes: 2

Related Questions