Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Parametrized query issue: Error: SCR-160021 Function 'query': too many arguments (X instead of 1).

Avatar

Level 1

Dear Community,

 

I am trying to use DBEngine query() command to select data from MSSQL database and I need to pass parameter/s to my query. I am following this tech spec - DBEngine.query() documentation.

There is an example showing how to pass a param - to do this use $(l), $(sz) as a param-holder/s (depending on param type), then pass param value/s separated by comma. Easy.

However, when I do so I get an exception: Error: SCR-160021 Function 'query': too many arguments (X instead of 1).

Where X is 2 if I pass a single param. It's 3 if I pass two params. And so on. Only query text is possible to pass as a single allowed function argument. 

 

This is my code lines:

 

 

var conn = application.getConnection();
result_Select = conn.query('SELECT 12345 as Col1, \'John Doe\') as Col2 WHERE 1 = $(l);', 1);

 

 

This is the exception:

 

 

Error: SCR-160021 Function 'query': too many arguments (2 instead of 1).

 

 

 

ACC v7.0 19.1 build 9032@d3b4522f of 01/07/2021.

 

Btw, the same problem for DBEngine.execute() command.

 

Is this a problem? Or I do something wrong?

Please help.

 

Thanks!

1 Reply

Avatar

Level 4

Hello @igorku ,

 

There is issue in your query as highlighted below:

Parvesh_Parmar_0-1655368463579.png

 

When I run the below query then it executed.

var cnx = application.getConnection()
result_Select = cnx.query('SELECT 12345 as Col1, \'John Doe\' as Col2 WHERE 1 = $(l);', 1);

 

Thanks.

Parvesh.

Avatar

Level 1

Hello Parvesh,

Thank you for detecting extra symbol, but actually I don't have it in my code. Not sure what's the problem on my end but this is what I am seeing.

igorku_1-1655465313425.png

 

On front is a Javascript code window. On back is a browser where I see the exception.

Any ideas?

 

Thanks!

Avatar

Employee Advisor

Hi @igorku 

Outside the error, why are you using JavaScript and not a Query activity within a Workflow?

In JavaScript, you would use queryDef object (https://experienceleague.adobe.com/developer/campaign-api/api/sm-queryDef-BuildQuery.html)

I would not recommend to use the DBEngine, you're exposing yourself to trouble down the line....

In your use case, why queryDef would work or Query activity in a workflow?

Thanks

Denis

Avatar

Administrator

Hi @igorku,

Were you able to resolve this query or do you still need more help here? Do let us know.

Thanks!