Dear Rick,
I am trying to return a Json cursor from a Rest function: your example runs rightly, but how to close the cursor before the end of procedure?
In this way I leave one cursor open every time.
Thank you for support
FUNCTION Customers()
SELECT * FROM Customers ;
ORDER BY Company ;
INTO CURSOR TCustomers
*** Override any property names with special case
JsonSerializer.PropertyNameOverrides = "firstName,lastName"
RETURN "cursor:TCustomers"
Simply add one line wherever you want:
Use in TCustomer
No Tore,
if I close the cursor the function I get "error reading JToken from JsonReader" because the function cannot find the cursor to return.
Can't you just close it at a later stage? Or zap it?
I develop a library of Rest services, everyone is called individually with its own parameters (for example, RestService1?Id=45&Time=Month).
I would like to close every temporary resource used by Rest functions before returning values, but I cannot close the cursor passed to Json.
Please is there any way to store Json return value to some variable before RETURN?
Json is just text, so you can do anything you like with it.
Oh, fantastic!
So how I capture
RETURN "cursor:TCustomers"
into a variable before closing the function?
I'm sorry, I really don't understand your problem. Hopefully Rick does, and can give you the help you want.
You can't close the cursor before the end of the routine because it's needed to render the JSON result.
There's an OnProcessComplete()
method that you can override. In that method you can check for open cursors or whatever and close them.
FUNCTION OnProcessComplete()
IF USED("TQuery")
USE IN TQuery
ENDIF
Note this fires for every request in your process class, so if the code is specific to your method you might have to filter by the script name. For Rest Services you can also use OnAfterCallComplete(lcResult)
which receives the final output of the request. This is probably the better way to go for a REST service.
ENDFUNC
+++ Rick ---