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-05-30 02:47:00

Johann
Member
Registered: 2022-05-30

Groovy Scripts - Importing variables or methods from another file

I currently have many groovy scripts with commonalities between them, but am having difficulty refactoring these parts into say a helper file.

I created a folder with my helper file. In the helper file, I simply define the package as `package folder_name` and a static variable containing some text. However, when I try to import the variable using `import static folder_name.Class.variable`, I run into an error saying:

The report could not be executed: net.datenwerke.rs.scripting.service.scripting.exceptions.ScriptEngineException: javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: ...unable to resolve class...


Would anyone happen to know how to import variables or methods from other files into groovy scripts? Thanks in advance!

Offline

#2 2022-05-30 09:22:30

IF_Eduardo
Administrator
Registered: 2016-11-01
Website

Re: Groovy Scripts - Importing variables or methods from another file

Hi Johann,

pls take a look here: https://reportserver.net/en/guides/scri … m-Scripts/

Regards,
Eduardo

Offline

#3 2022-05-30 10:18:46

Johann
Member
Registered: 2022-05-30

Re: Groovy Scripts - Importing variables or methods from another file

Will do, thank you Eduardo!

Offline

#4 2022-05-31 02:08:44

Johann
Member
Registered: 2022-05-30

Re: Groovy Scripts - Importing variables or methods from another file

Hi, I have tried following the example in the documentation here: https://reportserver.net/en/guides/scri … m-Scripts/

Just to share, in case anyone else is running into issues, there are two bugs in the sample code:

1. lib.groovy (line 11): return encrypt(ciphertext, (27 - k)
is missing a closing bracket, it should be: return encrypt(ciphertext, (27 - k))

2. encryptionTest.groovy (line 9): tout.println(dec(cipher, key))
is using the wrong method name, it should be: tout.println(dec(cipher, key))

Note also that the filename for the encryption test is encryptionTest.groovy, not encryptionTest.rs, as it is described in the documentation explanation part.

Offline

#5 2022-05-31 02:29:38

Johann
Member
Registered: 2022-05-30

Re: Groovy Scripts - Importing variables or methods from another file

eduardo wrote:

May I check if this solution is supposed to work when executing reports via "Administration > Reports" instead of through the terminal? I can execute my script successfully through the terminal, but when executing reports by right clicking on them and clicking "Execute", the library file cannot seem to be found:

Error: The report could not be executed: net.datenwerke.rs.scripting.service.scripting.exceptions.ScriptEngineException: javax.script.ScriptException: java.lang.RuntimeException: net.datenwerke.rs.terminal.service.terminal.vfs.exceptions.LocationDoesNotExistException: filesystem not found: lib.groovy ------- SCRIPT ERROR INFO ------- Script execution failed. error message: javax.script.ScriptException: java.lang.RuntimeException: net.datenwerke.rs.terminal.service.terminal.vfs.exceptions.LocationDoesNotExistException: filesystem not found: lib.groovy (java.lang.RuntimeException) script arguments: file: encryptionTest.groovy (id: 6234537, line 1) line number: 1 line: GLOBALS.exec("lib.groovy")


I tried running my script in the terminal with my working directory as the home directory, and found that the same error also occurred. If I were to change to the directory where the scripts are stored, then they execute fine via the terminal. How could I fix this issue? Thank you!

Offline

#6 2022-05-31 02:44:27

Johann
Member
Registered: 2022-05-30

Re: Groovy Scripts - Importing variables or methods from another file

In hindsight, I might have been unclear in my forum topic title: For context, I am trying to use Groovy scripts for Script Reporting, so I am trying to execute reports linked to Groovy scripts, rather than executing Groovy scripts by themselves. Hope this makes more sense!

Offline

#7 2022-06-01 04:22:48

Johann
Member
Registered: 2022-05-30

Re: Groovy Scripts - Importing variables or methods from another file

Another alternative I am considering is using the registry in the GLOBALS object: https://reportserver.net/en/guides/scri … n-Scripts/

However, this seems like an overkill. Does anyone know of a simpler solution? Thank you!

Offline

#8 2022-06-07 09:12:31

IF_Eduardo
Administrator
Registered: 2016-11-01
Website

Re: Groovy Scripts - Importing variables or methods from another file

Hi Johann,

we will check the documentation issues you mention and correct them.
You can use GLOBALS.exec("lib.groovy") as documented here https://reportserver.net/en/guides/scri … m-Scripts/ and you mentioned here: https://forum.reportserver.net/viewtopi … 9499#p9499

Regards,
Eduardo

Offline

#9 2022-06-07 09:15:22

Johann
Member
Registered: 2022-05-30

Re: Groovy Scripts - Importing variables or methods from another file

Got it, thank you!

Offline

#10 2022-07-19 11:42:38

IF_Eduardo
Administrator
Registered: 2016-11-01
Website

Re: Groovy Scripts - Importing variables or methods from another file

Hi Johann,

note that we corrected the online documentation issues you mentioned.

Regards,
Eduardo

Offline

#11 2022-07-20 01:17:22

Johann
Member
Registered: 2022-05-30

Re: Groovy Scripts - Importing variables or methods from another file

Hi Eduardo,

Thank you for the update!

Regards,
Johann

Offline

Board footer

Powered by FluxBB