JSONSqlQueryResult ( fieldlist ; keylist ; keytypes ; fromwhereclause )
Execute SQL-statement and format directly into JSON, without dependencies (for fmp 18+)
Average rating: 4.5 (2 votes) Log in to vote
Menno van Beek - Show more from this author
Van Beek Zakelijke Software https://www.vbzs.nl |
List (
GetFieldName ( SalesLines::Number ) ;
GetFieldName ( SalesLines::Description ) ;
GetFieldName ( SalesLines::Price ) ;
GetFieldName ( SalesLines::Amount ) ) ;
"" ; /* keylist may be left empty, see description in function */
List ( JSONNumber ; JSONString ; JSONNumber ; JSONNumber ) ; /* keytypeslist may be left empty. Do not quote() the keytypes, only use JSONString/JSONNumber or 1/2. */
"FROM \"SalesLines\" WHERE \"SalesLines\".\"SalesID\"=123456" )
{
"Amount" : 10,
"Description" : "item",
"Number" : 1,
"Price" : 10
},
{
"Amount" : 27,
"Description" : "items",
"Number" : 3,
"Price" : 9
}
]
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
This function is intended for straightforward SQL-statements and to have the result poured directly into JSON-format. The function requires fmp 18+ and does not depend on any other custom-function.
Supply at least a list of "Fully Quallified Field Names" and a FROM and WHERE clause. The function will then create the keynames from the fieldlist, but you can also set your own keylist.
The same for the keytypes. Provide a list with only JSONString and JSONNumber values or leave it empty to have the function choose by checking the fieldtypes.
Comments
Lazarus Sismanis, Decision Group Nov 19, 2022 |
||
Couldn't get the 'keytypes' to work when trying to select number fields as JSONString. Especially problematic when the number field is a UUID(Number).. Also, in the code, 'fromwhereclause' needs to be replaced with 'clauses'. If these are fixed, this is a great custom function! |
||
Menno van Beek, Van Beek Zakelijke Software Nov 19, 2022 |
||
Thanks for the feedback, I corrected "clause" into "fromwhereclause". On the list of keytypes: the keytypes should not be quoted. Enter the list of keytpes as: List ( JSONNumber ; JSONString ) or List ( 2 ; 1 ) or jusr leave it empty to use the native fieldtype (which will always be JSONString if it is not a Number-field) |
||
Lazarus Sismanis, Decision Group Nov 19, 2022 |
||
Thank you so much! Got it working as described. | ||
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.