SuiteQL: Invalid number of parameters. 

This error was so hard to find, I thought I’d document it. The error message read: “Invalid number of parameters. Expected: 0. Provided: 3

I was coding a SuiteQL query in SuiteScript Version 2.0. Here’s an example.

If you happen to make the mistake I made and add an extra comma at the end of one of the column definitions, BOOM!

This is relatively easy to spot is a small query. However, in a much larger query with lots of columns, it’s easy to miss. I’ll attest to that. Here is the code in case you want to try this at home.

require(['N/query'],
    function (query) {
        log.debug('start');

        const MY_SQL_CONSTANT = 
        "select " +
        "      BUILTIN.DF(tl.item) as item_name\n" +
        "    , tl.linesequencenumber as line\n" +
        "from transactionline tl\n" +
        "where tl.transaction = ? " +
        "   and tl.item is not null " +
        "order by tl.linesequencenumber";

        var results = query.runSuiteQL({
            query: MY_SQL_CONSTANT, 
            params: [your transaction id here]
        }).asMappedResults();

        log.debug(results[0].item_name);

        log.debug('finished');
    }
)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s