Run a SQL query with parameter from script called via api

Hi, everyone!

I want to implement following solution:

1. Create a custom SQL query which returns all of employee assignments, such as ad groups, entitlements, requests and relations between these objects with filtering by personnelnumber.

2. Create a script  which should call a SQL query with parameter (personnelnumber) which should be transferred to this SQL query.

3. Call the script via OIM api/script/<scriptname>

4. Return the data loaded by SQL query in response.

I've already created a sql query and tested it in API designer, so parameter works fine and the query works as expected. Already read the tech doc and topics here related to the scripts, api and sql queries and still not understand how to build a process which allow me to achieve the described goal.

Here is the sample of the script:

Public Function CCC_TestSQL(ByVal TN As String) As String

Dim runner = Session.Resolve(Of VI.DB.DataAccess.IStatementRunner)()
runner.SqlExecute("CCC_TestSQL", {QueryParameter.Create("TN", 42)})

End Function

How can I pass a TN parameter to the SQL query here?

Thanks in advance!