Support

Lorem ipsum dolor sit amet:

24h / 365days

We offer support for our customers

Mon - Fri 8:00am - 5:00pm (GMT +1)

Get in touch

Cybersteel Inc.
376-293 City Road, Suite 600
San Francisco, CA 94102

Have any questions?
+44 1234 567 890

Drop us a line
info@yourdomain.com

About us

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec.

Chapter 7. Script Datasinks

7. Script Datasinks

Script datasinks are your swiss army knife when it comes to sending your reports/your data to custom locations or when you need any logic or any additional files. Basically, you can use script datasinks to send your reports/your data to virtually any location you may need.

When defining a script datasource, you have the following variables available to use:

data contains the report or the data. Depending on the type of the data, this may be a String or a byte array. Note you can always use ReportService.createInputStream(Object) for creating an InputStream out of the data object.
report the same as the ''data'' variable above. Recommended is to use data, report is included for consistency.
script the FileServerFile containing the script of the datasink. You can use script.data for accessing the data in the script, or script.contentType for its content-type, or script.name for its name. Refer to the FileServerFile javadocs for a complete overview.
user the User executing the script datasink.
datasinkConfiguration the datasink configuration object which contains the selected filename of the report/the data. This may be accessed with datasinkConfiguration.filename.

An example script datasink is shown below. It creates a ZIP containing the report/the data, adds the groovy script to the ZIP and sends this per email to a given user list.

The script is available here: https://github.com/infofabrik/reportserver-samples/blob/main/src/net/datenwerke/rs/samples/tools/datasinks/scriptDatasinkPerEmail.groovy.

import net.datenwerke.rs.core.service.mail.MailBuilderFactory
import net.datenwerke.rs.core.service.mail.MailService
import net.datenwerke.security.service.usermanager.UserManagerService
import net.datenwerke.rs.utils.misc.MimeUtils
import net.datenwerke.rs.core.service.mail.SimpleAttachment
import java.nio.file.Paths

import java.time.LocalDateTime

def mailBuilder = GLOBALS.getInstance(MailBuilderFactory)
def mailService = GLOBALS.getInstance(MailService)
def userService = GLOBALS.getInstance(UserManagerService)
def mimeUtils = GLOBALS.getInstance(MimeUtils)

// the user ids. They have to exist and the ids are passed as long (L)
def to = [123L]
def subject = 'Script datasink'
def content = "ReportServer script datasink ${LocalDateTime.now()}"
// name of the zip
def attachmentFilename = 'data.zip'

def attachments = [
   new SimpleAttachment(data, // you can also use report
   mimeUtils.getMimeTypeByExtension(datasinkConfiguration.filename),
   datasinkConfiguration.filename),
   // add the script
   new SimpleAttachment(script.data, script.contentType, script.name)
]

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

mailService.sendMail mail

InfoFabrik GmbH

Wir wollen, dass alle Unternehmen, Institutionen und Organisationen, die Daten auswerten, selbständig und zeitnah genau die Informationen erhalten, die sie für ein erfolgreiches Arbeiten benötigen.

InfoFabrik GmbH
Klingholzstr. 7
65189 Wiesbaden
Germany

+49 (0) 611 580 66 25

Kontaktieren Sie uns

Bitte rechnen Sie 9 plus 1.
Copyright 2007 - 2024 InfoFabrik GmbH. All Rights Reserved.

Auf unserer Website setzen wir Cookies und andere Technologien ein. Während einige davon essenziell sind, dienen andere dazu, die Website zu verbessern und den Erfolg unserer Kampagnen zu bewerten. Bei der Nutzung unserer Website werden Daten verarbeitet, um Anzeigen und Inhalte zu messen. Weitere Informationen dazu finden Sie in unserer Datenschutzerklärung. Sie haben jederzeit die Möglichkeit, Ihre Einstellungen anzupassen oder zu widerrufen.

Datenschutzerklärung Impressum
You are using an outdated browser. The website may not be displayed correctly. Close