Announcement

Migration of this forum

Dear users of this forum,

we are pleased to inform you that we will be updating the software behind this forum in the near future.

Existing posts, users and categories will remain untouched.

Important:

  • Each user will need to reset their password.
  • Please select "I forgot my password".
  • Enter the email address you used to register in this forum.
  • You will receive an email with a link to set a new password.
  • Please choose a new (secure) password and confirm the process.

We will keep you informed in the pinned thread.

Kind regards,
Your ReportServer Team


Migration des Forums

Liebe Nutzer dieses Forums,

wir freuen uns, euch mitteilen zu können, dass wir in naher Zukunft die Software hinter diesem Forum aktualisieren werden.

Existierende Beiträge, Nutzer und Kategorien bleiben weiterhin bestehen!

Wichtig:

  • Jeder Nutzer muss sein Passwort neu vergeben.
  • Wählt dazu einfach "Ich habe mein Passwort vergessen".
  • Gebt die E-Mail-Adresse ein, mit der ihr registriert seid.
  • Ihr erhaltet eine E-Mail mit einem Link zur Passwortvergabe.
  • Bitte wählt ein neues (sicheres) Passwort und bestätigt den Vorgang.

Wir halten euch im angepinnten Beitrag auf dem Laufenden!

Mit vielen Grüßen
Euer ReportServer Team

#1 2022-06-08 05:56:52

Johann
Member
Registered: 2022-05-30

Groovy Scripts Reports - How to import SQL queries from .sql file

Would like to achieve the following:
1. Consolidate all SQL queries in one place so debugging and changes could be easier
2. Enable syntax highlighting for SQL code as currently there is no highlighting in Groovy files for SQL queries (using IntelliJ IDE)

Am wondering if it is possible to factor out my SQL queries from my groovy script reports into a .sql file, and then import the relevant queries into the script reports. How should I go about doing this?

Offline

#2 2022-06-08 08:50:39

IF_Eduardo
Administrator
Registered: 2016-11-01
Website

Re: Groovy Scripts Reports - How to import SQL queries from .sql file

Hi Johann,

your groovy script should be able to parse the .sql file and look for the relevant query. You would have to write a parser/lookup for that, but it should be doable.

Regards,
Eduardo

Offline

#3 2022-06-16 10:54:29

Johann
Member
Registered: 2022-05-30

Re: Groovy Scripts Reports - How to import SQL queries from .sql file

Hi Eduardo,

I am trying to read my SQL query from .sql using Groovy's File library. I have the following line of code:

def query1 = new File('/fileserver/bin/queries/data1.sql').text

where my SQL file data1.sql is under the ReportServer path '/fileserver/bin/queries'. However, I am getting the following error when I try to execute my Groovy script:

The report could not be executed: net.datenwerke.rs.scripting.service.scripting.exceptions.ScriptEngineException: javax.script.ScriptException: java.io.FileNotFoundException: /fileserver/bin/queries/data1.sql (No such file or directory)
------- SCRIPT ERROR INFO -------
Script execution failed.
error message: javax.script.ScriptException: java.io.FileNotFoundException: /fileserver/bin/queries/data1.sql (No such file or directory) (java.io.FileNotFoundException)
script arguments:
file: ...
line: def query1 = new File('/fileserver/bin/queries/data1.sql').text

May I ask how I could fix this? Thank you!

Last edited by Johann (2022-06-17 06:59:17)

Offline

#4 2022-06-17 07:06:15

Johann
Member
Registered: 2022-05-30

Re: Groovy Scripts Reports - How to import SQL queries from .sql file

Resolved: Apparently we cannot use the Java/Groovy File class.

According to the documentation (https://reportserver.net/en/guides/scri … -to-Files/), use:

 def query = GLOBALS.services['fileService'].read('/fileserver/bin/queries/data1.sql') 

Offline

#5 2022-06-17 08:12:21

IF_Eduardo
Administrator
Registered: 2016-11-01
Website

Re: Groovy Scripts Reports - How to import SQL queries from .sql file

Hi Johann,

yes, in order to use the internal reportserver file system you have to work with the services to read the file contents.

Thanks for posting your solution.

Regards,
Eduardo

Offline

#6 2022-06-17 12:09:15

Johann
Member
Registered: 2022-05-30

Re: Groovy Scripts Reports - How to import SQL queries from .sql file

Got it, thank you Eduardo!

Offline

Board footer

Powered by FluxBB