0

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

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.