#1 2023-10-20 12:15:05

msx008
Member
Registered: 2023-09-20

Script report <= query wrapper

hello
I have a groovy script with embedded highcharts
before the sql was in the script and I will get the parameters using parameterMap
I wanted to put it in the query wrapper, but I don't know how to retrieve it or do it, I'm not a developer
I tried def query = parameterMap['_RS_QUERY'], doesn't work


to test I put it in the description (sorry) by removing the parameters, it works, otherwise I got an error message
old parameter = .... AND EXTRACT(month FROM ai.invoice_date) = $month ...

so without parameter below works
def query = parameterMap['_RS_REPORT_DESCRIPTION']
def result = sql.rows(query)

It's probably in the documentation, but I didn't understood or seen

If you can help me  to put the query in wrapper, with parameter (formated like groovy or RS) and retrieve then in the script 

regards

ps: not sure to be clear, sorry

Offline

#2 2023-10-23 10:20:08

adrian1703
Moderator
Registered: 2021-10-29

Re: Script report <= query wrapper

Hi,

Groovy replaces placeholder variables inside a String at runtime with allows you write:
def myVar = "world"
def myString = "Hello $myVar"
print(myString) --> "Hello world"
For this to work, myVar needs to be defined before myString. This might be the issue which causes your imported query not to be formatted.


If I understood your problem correctly your variables inside the query string are not replaced with parameters.
In that case you can try to replace them after importing the script:

def query = parameterMap['_RS_REPORT_DESCRIPTION']
query = query.replace('\$month', parameterMap['month']) // '$' needs to be escaped with '/'
def result = sql.rows(query)

Let me know if that works for you.

Kind regards,
Adrian

Offline

#3 2023-10-23 11:22:36

msx008
Member
Registered: 2023-09-20

Re: Script report <= query wrapper

hello
so , thanks four your help ,
I adapted it to my needs, it helped me a lot, I learned cool
my script works
by the way, can I put it in query wrapper rather than in description, if so how can I recover it?
regards

Offline

Board footer

Powered by FluxBB