Home > Forum > Actions > SQL query with JSON array

SQL query with JSON array
0

Hi all!

We want to add some rows to an item list with 'Change item lists values' action.

The SQL query should take a JSON array (which is perfectly valid) from UI element and return a table for adding new rows to this item list.

Unfortunately this does not work. There seems to be some parsing on Webcon side, which eliminates all elements in the JSON array, apart from the separator, which results in SQL error (JSON text is not properly formatted. Unexpected character ...).

The attached query works fine in SQL management studio.

Can anybody tell me, what's going wrong here or show some alternatives or workarounds?

Thanks a lot & best regards, Nik

MVP

Have you tried that SQL on Webcon database in SQL managment studio, or on another one?

WEBCON is using 120 Compatibility Level for SQL Database according to this: https://community.webcon.com/posts/post/compatibility-level-of-webcon-bps-databases-good-practices/323/3
and the OPENJSON requires it at 130: https://docs.microsoft.com/en-us/sql/t-sql/functions/openjson-transact-sql?view=sql-server-ver16

If it was tested on another database, then this could be the reason.

In reply to: Maksymilian Stachowiak

Have you tried that SQL on Webcon database in SQL managment studio, or on another one?

WEBCON is using 120 Compatibility Level for SQL Database according to this: https://community.webcon.com/posts/post/compatibility-level-of-webcon-bps-databases-good-practices/323/3
and the OPENJSON requires it at 130: https://docs.microsoft.com/en-us/sql/t-sql/functions/openjson-transact-sql?view=sql-server-ver16

If it was tested on another database, then this could be the reason.

Hi Maksymilian!

Thanks for the good tipp.

Unfortunately it's the same database and compatibility level is set here to 130.

If I test (in Designer Studio) the following query:

SELECT '[{"id" : 1,"code":"925006300000","name": "Test 1"},{"id" : 1,"code":"925003600000","name": "Test 2"}]' AS DET_ATT1

I get the following result:

[',']

It seems like Webcon is trying to substitute everything within {} to empty values.

Maybe because Variables in Webcon have the same pattern than JSON objects, e.g. {WFD_ID}.

Unfortunately I have no idea of how to fix this.