#1 2024-07-15 12:14:32

Geoffrey
Member
From: Loerrach (Germany)
Registered: 2024-02-20
Website

Script Datasinks E-mail

Hi,

On RS4.6.3-6104 I am trying your DataSink example script of the documentation :

https://reportserver.net/de/dokumentati … -datasinks

datasink

However I have an exception when I run the schedule:

datasink

Full logs

scriptDatasinkPerEmail.groovy


Do have an idea what I have wrong here?

Thanks,

Regards,

Geoffrey

Offline

#2 2024-07-17 05:58:37

adrian1703
Moderator
Registered: 2021-10-29

Re: Script Datasinks E-mail

Hello,
You have a syntax error in your script.

to.collect{..} only works if "to" is a collection/iterable.

This is were your script differs from the example.
def to = 6L -> it should be def to = [6L]

Kind regards,
Adrian

Offline

#3 2024-07-17 08:34:04

Geoffrey
Member
From: Loerrach (Germany)
Registered: 2024-02-20
Website

Re: Script Datasinks E-mail

Hello Adrian,

I am not sure that this is the problem. I already tried differents syntax.
For example if I put :
def to = [39431L,33990L]

I have the same error, see detail

Thanks,

regards,

Geoffrey Hohler

Offline

#4 2024-07-17 09:33:16

adrian1703
Moderator
Registered: 2021-10-29

Re: Script Datasinks E-mail

Hello,

I see. The problem seems to be the following :

mailBuilder.create() expects the types (String, String, List) as arguements.
In this example the following types are given: (String, org.codehaus.groovy.runtime.GStringImpl, ArrayList)

The second arguement makes the call fail.
def subject = 'Script datasink'
def content = "ReportServer script datasink ${LocalDateTime.now()}"
In groovy 'asdf' indicates String and "asdf" indicates GString. You can type-convert using the "as" keyword
So either do the following

String content = "ReportServer script datasink ${LocalDateTime.now()}" as String
or pass it as String in your method call

def mail = mailBuilder.create(
      subject,
      content as String,
      to.collect{userId -> userService.getNodeById(userId)})
      .withAttachments(attachments)
      .withZippedAttachments(attachmentFilename)
      .build()

Both should remove this error.

Kind regards,
Adrian

Offline

#5 2024-07-17 09:54:00

Geoffrey
Member
From: Loerrach (Germany)
Registered: 2024-02-20
Website

Re: Script Datasinks E-mail

Thanks for your feedback, however your suggestion seems to not resolve the problem completely:

error message: No signature of method: com.sun.proxy.$Proxy168.create() is applicable for argument types: (String, String, ArrayList) values: [Script datasink, ReportServer script datasink 2024-07-17T09:42:19.175826, [User{ID=39431, First name=Lemarechal, Last name=Gregory}, ...]]
Possible solutions: create(java.lang.String, java.lang.String, java.util.List, javax.mail.internet.InternetAddress), grep(), stream(), iterator() (groovy.lang.MissingMethodException)

Both of your suggestion seems not to give the same result.

Thanks,

Regards,

Geoffrey

Last edited by Geoffrey (2024-07-17 09:57:07)

Offline

#6 2024-07-18 05:13:05

adrian1703
Moderator
Registered: 2021-10-29

Re: Script Datasinks E-mail

Hello Geoffrey,
I took another look. I seems like there was a bugfix that changed the signatur 5 months ago which is not yet reflected in scripting examples:

-    public MailBuilder create(@Assisted("subject") String subject, @Assisted("body") String body, List<User> recipients);
+   public MailBuilder create(@Assisted("subject") String subject, @Assisted("body") String body, List<User> recipients,
+         InternetAddress from);

This means that the create method now requires an additional parameter InternetAddress "from".
You could either manually create such an object for example like this:
import javax.mail.internet.InternetAddress
def user = userService.getNodeById(6)
String mailFrom = user.getEmail();
String mailFromName = user.getFirstname() + " " + user.getLastname();
def iaddress = new InternetAddress(mailFrom, mailFromName);

and pass it along:
def mail = mailBuilder.create(
        subject,
        content,
        to.collect{userId -> userService.getNodeById(userId)},
        iaddress)
        .build()

or use the service method:

MailService
InternetAddress getMailFrom(User user, Optional<EmailDatasink> datasink); (here the passed datasink is a fallback if the given user has no email)

I hope this fixes your issue.

Kind regards,
Adrian

Offline

#7 2024-07-18 13:09:23

Geoffrey
Member
From: Loerrach (Germany)
Registered: 2024-02-20
Website

Re: Script Datasinks E-mail

Hello Adrian,

Many thanks for you answer, now it works fine!
However it think that you should adapt the documentation accordantly.

I have a another the question: How in this script can I get the Ids of  Recipient users configured I the schedule ? Instead to have it hardcoded in the script.

Thanks,

Regards,

Geoffrey

Offline

#8 2024-07-29 15:00:38

Geoffrey
Member
From: Loerrach (Germany)
Registered: 2024-02-20
Website

Re: Script Datasinks E-mail

Hi,

Do you know how in the Datasink script I can get user Ids/E-mail addresses of the user configured as recipient on the schedule ?

scheduler_recipiant.PNG

Thanks,

Regards,

Geoffrey

Offline

#9 2024-08-08 11:25:41

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Script Datasinks E-mail

Hi Geoffrey,

currently, the data available in script datasinks is shown here: https://reportserver.net/de/dokumentati … -datasinks

We raised a new ticket RS-8593 for adding the scheduler job infos to this list.

Regards,
Eduardo

Offline

#10 2024-08-08 13:28:26

Geoffrey
Member
From: Loerrach (Germany)
Registered: 2024-02-20
Website

Re: Script Datasinks E-mail

Hi Eduardo,

OK this means that is it currently not possible? I have already see this page of the documentation, but I was surprised that there a so little number variables available, this is why I am asking.

When do you think that it will be possible ?

The idea behind this, is instead to send the report as attachment to the users, to save the document on the file system and send by e-mail a HTTP link pointing to the saved report.


Thanks,

regards,

Geoffrey

Offline

#11 2024-08-09 08:07:22

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Script Datasinks E-mail

Hi Geoffrey,

this ticket is currently on the development queue. We will write here when we have more information.

Regards,
Eduardo

Offline

Board footer

Powered by FluxBB