#1 2019-07-23 20:00:56

jheadlee
Member
Registered: 2019-07-15

Passing Report Parameters via URL in Script

Ok I have my report engine setup for access via URL except for the final piece. Passing the report parameters by URL.

Ie:

http://reports01.domain.foo/reportserve … 7%20JBLOSE

The script pulls in 3 args, email to send report to, report to run, parameters to send report.

I'm stuck on the last piece, I assume I need to setup a parameterSet and then push that to the report engine. All the examples get me close, and otherwise no love.

can you point me to docs?

        Report extraReport = reportService.getReportById(Integer.parseInt(args[1]));
        CompiledReport extraReportCompiled = extraReportCompiled = reportExec.execute(extraReport, "PDF", ReportExecutionConfig.EMPTY_CONFIG);

Offline

#2 2019-07-29 07:29:21

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Passing Report Parameters via URL in Script

Hi jheadlee,

for setting parameters you can use the following:

Set<ParameterInstance> parameterSet = report.getParameterInstances();
    
    for(ParameterInstance param : parameterSet) {
      String name = param.getDefinition().getName();
      if(param instanceof TextParameterInstance) { // we are looking for a text parameter
        TextParameterInstance textParam = (TextParameterInstance) param; 
        if(name.equals("MY_PARAMETER")){ // this is the one we want to set
          textParam.setValue("NEW VALUE"); // we set the new value of the parameter
        }
      }   
    }

The parameter has to be defined in the report with the key MY_PARAMETER.

Regards,
Eduardo

Offline

#3 2019-08-22 19:17:47

jheadlee
Member
Registered: 2019-07-15

Re: Passing Report Parameters via URL in Script

So I had to make some tweaks as you left out 2 key imports, thank god for unzip -v :>

import net.datenwerke.rs.core.service.parameters.entities.ParameterInstance;
import net.datenwerke.rs.base.service.parameters.string.TextParameterInstance;

So you can see by the log, it's not pulling default values for the params, and it injects the customerID which is the intent. And it comes up blank. So it's not actually pushing the value. I'm going to create a simple ARG reporting script to test this, but it looks like either:

- The default values are pissing it off
- It's not passing the new param into the set w/ the setValue when it executes.

22-Aug-2019 15:08:24.055 SEVERE [ajp-apr-8009-exec-2] java_util_logging_Logger$log$0.call getlogginginfo Name: emailTo
22-Aug-2019 15:08:24.056 SEVERE [ajp-apr-8009-exec-2] java_util_logging_Logger$log$0.call getlogginginfo param val - null
22-Aug-2019 15:08:24.056 SEVERE [ajp-apr-8009-exec-2] java_util_logging_Logger$log$0.call getlogginginfo Name: StartDate
22-Aug-2019 15:08:24.056 SEVERE [ajp-apr-8009-exec-2] java_util_logging_Logger$log$0.call getlogginginfo param val - null
22-Aug-2019 15:08:24.056 SEVERE [ajp-apr-8009-exec-2] java_util_logging_Logger$log$0.call getlogginginfo Name: CustomerID
22-Aug-2019 15:08:24.056 SEVERE [ajp-apr-8009-exec-2] java_util_logging_Logger$log$0.call getlogginginfo param val - null
22-Aug-2019 15:08:24.057 SEVERE [ajp-apr-8009-exec-2] java_util_logging_Logger$log$0.call getlogginginfo text param val - 0001006925
22-Aug-2019 15:08:24.057 SEVERE [ajp-apr-8009-exec-2] java_util_logging_Logger$log$0.call getlogginginfo param val2 - 0001006925
22-Aug-2019 15:08:24.057 SEVERE [ajp-apr-8009-exec-2] java_util_logging_Logger$log$0.call getlogginginfo Name: EndDate
22-Aug-2019 15:08:24.057 SEVERE [ajp-apr-8009-exec-2] java_util_logging_Logger$log$0.call getlogginginfo param val - null


Just my $0.02 but having the ability to pass the p_<PARAMNAME> into the script and have a payload of params passed to the report/engine, and the quick ability to add email would be a huge selling point. I am sending 400+ KPI reports to individuals and rollups for managers, etc and over 2400 customer invoice change audits just to start. And this is a key piece.. I think you could sell alot more licenses if that was a bit more automated, or started a script library to sell the enterprise model w/ a bit more cookie cutter script functions.

Thanks for your help, I love the products, speed, power, just gotta get past this last piece and since no errors I'm stumped.

Current code:

import java.util.HashMap;

import net.datenwerke.rs.core.service.sendto.hooks.SendToTargetProviderHook;
import net.datenwerke.rs.core.service.sendto.hooks.adapter.SendToTargetProviderHookAdapter;
import net.datenwerke.rs.core.client.sendto.SendToClientConfig;
import net.datenwerke.rs.core.service.mail.MailService;
import net.datenwerke.rs.core.service.mail.SimpleAttachement;
import net.datenwerke.rs.core.service.mail.SimpleMail;
import net.datenwerke.rs.core.service.parameters.entities.ParameterInstance;
import net.datenwerke.rs.base.service.parameters.string.TextParameterInstance;
import net.datenwerke.rs.core.service.reportmanager.parameters.ParameterSet;
import net.datenwerke.rs.core.service.reportmanager.parameters.ParameterSetFactory;
import net.datenwerke.rs.core.service.reportmanager.ReportExecutorService;
import net.datenwerke.rs.core.service.reportmanager.ReportService;
import net.datenwerke.rs.core.service.reportmanager.engine.CompiledReport;
import net.datenwerke.rs.core.service.reportmanager.engine.config.ReportExecutionConfig;
import net.datenwerke.rs.core.service.reportmanager.entities.reports.Report;
import net.datenwerke.rs.core.service.reportmanager.exceptions.ReportExecutorException;
import net.datenwerke.rs.core.service.sendto.hooks.SendToTargetProviderHook;
import net.datenwerke.rs.scripting.service.scripting.scriptservices.CallbackRegistry;
import net.datenwerke.scheduler.service.scheduler.entities.AbstractJob;
import net.datenwerke.rs.core.service.reportmanager.engine.basereports.CompiledHtmlReportImpl;
import java.util.HashMap;
import groovy.xml.*;
import java.util.logging.Level;
import java.util.logging.Logger; 

//def HOOK_NAME = "MY_SEND_TO"

reportService = GLOBALS.getInstance(ReportService.class)
reportExec = GLOBALS.getInstance(ReportExecutorService.class)
mailService = GLOBALS.getInstance(MailService.class)
logger = Logger.getLogger(getClass().getName());
LOG_PREFIX = "getlogginginfo "; // optional

String doSendMail() {
 
  try {

        Report extraReport = reportService.getReportById(47994);
   
        Set<ParameterInstance> parameterSet = extraReport.getParameterInstances();
        logger.log(Level.SEVERE, LOG_PREFIX + "=== START getLoggingInfo =========\n");
        tout.println("=== START getLoggingInfo =========");
        for(ParameterInstance param : parameterSet) {
          String name = param.getDefinition().getName();
          logger.log(Level.SEVERE, LOG_PREFIX + "Name: " + name);
          logger.log(Level.SEVERE, LOG_PREFIX + "param val - "  + param.getValue());
          if(param instanceof TextParameterInstance) { // we are looking for a text parameter
            TextParameterInstance textParam = (TextParameterInstance) param;
           
            if(name.equals("CustomerID")){ // this is the one we want to set
              textParam.setValue(args[0]); // we set the new value of the parameter
              logger.log(Level.SEVERE, LOG_PREFIX + "text param val - " + textParam.getValue());
                    logger.log(Level.SEVERE, LOG_PREFIX + "param val2 - " + param.getValue());
            }
          }   
        }
   
        CompiledReport extraReportCompiled = extraReportCompiled = reportExec.execute(extraReport, "PDF", ReportExecutionConfig.EMPTY_CONFIG);
   
        SimpleMail mail = mailService.newSimpleMail();
        mail.setSubject("Test Report");
        mail.setToRecipients("jheadlee@evolveip.net");
    //    mail.setFrom("boss@evolveip.net");

        SimpleAttachement extraReportAttachement = new SimpleAttachement(extraReportCompiled.getReport(),
                extraReportCompiled.getMimeType(), "Report.pdf");
        // Attach the files
        mail.setContent("Some text", extraReportAttachement);

        // send mail
        mailService.sendMail(mail);

        return "Send the report via mail.";
   
    } catch (ReportExecutorException e) {
            e.printStackTrace();
    }
}

def writer = new StringWriter()

new MarkupBuilder(writer).html {
   head {
     title ( 'Hello World' )
   }
   body {
     h1(style: 'color: #f00', "Hello")
     p("Isn't that an easy way to create a report?")
   //  p("Report param is " + parameterMap['CustomerID'])
     
   }
}

doSendMail()
return writer.toString()

Offline

#4 2019-08-23 08:41:10

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Passing Report Parameters via URL in Script

Hi jheadlee,

your original question was:

jheadlee wrote:

The script pulls in 3 args, email to send report to, report to run, parameters to send report.

I'm stuck on the last piece, I assume I need to setup a parameterSet and then push that to the report engine. All the examples get me close, and otherwise no love.

and that's what we responded to. In your last post you are talking about some things that weren't included in the original question:
- default parameters
- send to email

-What are you actually trying to do ? What is the use case ? Please describe this.
-Is there any special reason you are using a "send to" script to send per email instead of the default "send to- via email" functionality ? What are you trying to do in your script that is not available with the default functionality ?
-Which parameters have a "default value" in your case? Please post some screenshots.

Regards,
Eduardo

Offline

#5 2019-08-23 17:38:47

jheadlee
Member
Registered: 2019-07-15

Re: Passing Report Parameters via URL in Script

I'm more than happy to use built-in functionality and it has not been clear that this use case works. We do alot on scheduled reports for 1:1 work, or 1:many for manager reports for instance. No issues.

The use case I am trying to solve since the URL is the closest thing to an API is for many:1 reports. By that I mean a stock report like our invoice adjustment reports to our customers. It's always going to be a dynamic list of upwards of 1000s that had actionable changes in billing that will arrive on their next bill. We send this out monthly.

I need to send the report dynamically to the proper customer billing email contact email address, by customer ID. So I am running a cron shell, pull the data from db2 to get the unique list of customers and their contacts to then for each a CURL command to this call.

The issue is passing the customerID parameter is not working, and I can see where if this works I would add a vendor API for your system to be able to pass JSON or some key/value pair in for the parameters on these larger report sends. And it's not working, that is what I need help with, how to ultimately take what is done if I were to use the report HTML page I could use p_CustomerID, p_StartDate and p_EndDate to control this report as needed. AND I couldn't see how to email that dynamically so I went to the scripts to be able to pass who to email the report to in the first place.

I think if I can get help in either if the parameters in the code above are early bound to the report I am trying to run, or if the default parameters are late bound (seems like it as all values are null) and overwriting them. Or do I have to pass the parameters to the report execution because they aren't bound at all.

Offline

#6 2019-08-23 17:45:53

jheadlee
Member
Registered: 2019-07-15

Re: Passing Report Parameters via URL in Script

Screenshots, is there something BBCode supports natively??

https://imgur.com/VroFqui

https://imgur.com/dvfs5Nk

https://imgur.com/OC0u37F

I removed the email param, as I was trying to get it to pass into ReportServer and not need scripting, so that has been removed.

Let me know please, this is the last piece of truly loving this thing 100/100.

Offline

#7 2019-09-26 07:36:26

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Passing Report Parameters via URL in Script

Hi jheadlee,

we will look at this in ticket RS-3673.

Regards,
Eduardo

Offline

Board footer

Powered by FluxBB