Jaspersoft / jrs-rest-php-client

REST API wrapper for PHP used to interact with JasperReports Server
GNU Lesser General Public License v3.0
63 stars 59 forks source link

Pass Parameters Directly? #11

Closed joshabts closed 10 years ago

joshabts commented 10 years ago

Is it possible to pass parameters directly using the PHP client or can that only be done via input controls? The documentation doesn't seem to call out passing direct parameters but rather only input controls.

Actine commented 10 years ago

@joshabts What do you mean by passing parameters directly? Can you please give an example of such request? (URL, body)

joshabts commented 10 years ago

Sorry for not being more clear, I can see how parameters is rather vague. By passing parameters directly I was referring to the report parameters defined within the report themselves. So if my report is /reports/userHistory for example and in that report there is a parameter defined as $P{user_id}, how do I pass user_id to the report through runReport if not using input controls?

I have tried something similar to this, but again, it only seems to apply to input controls, not the parameter in the report directly.

$client = new Jaspersoft\Client\Client(JASPERREPORTS_URL, // Hostname JASPERREPORTS_USER, // Username JASPERREPORTS_PASS // Password ); $controls = array('user_id' => array('123')); $report = $client->reportService()->runReport('/reports/userHistory', 'pdf', null, null, $controls);

Actine commented 10 years ago

I am sorry, but I still don't understand the issue you experience. Whenever you pass a parameter value to a report - regardless whether you use Web UI, REST API or its clients, there's no way to pass parameter values to a report other than using input controls. For each parameter in query, like $P{user_id} you have to define an input control in your report - that's the core thing about JRS reporting. A parameter is always represented by an input control with the same ID.

The client is built that way that you have to create an assoc array of input controls and pass them to the report you want to run. Under the hood this triggers an HTTP request GET /rest_v2/reports/reports/userHistory.pdf?user_id=123. If you prefer doing it this way, you may just request it using get_file_contents and without needing the client, like:

$report = get_file_contents(JASPERREPORTS_URL . '/rest_v2/reports/reports/userHistory.pdf?user_id=123&j_username=' . JASPERREPORTS_USER . '&j_password=' . JASPERREPORTS_PASS);

(however you'll have to add error handling yourself then)

joshabts commented 10 years ago

I guess I am confused then, because I was previously using the SOAP API and in that I never defined any input controls. The report simply had the parameters which I appended to the URI using urlencode.

The only place I can see to define input controls is through the jasperserver web UI itself, unless I am missing something in Jaspersoft Studio to actually define an input control within a report jrxml file itself? Or I can add them via the repository view in Studio but don't see how to attach them to a report (and I prefer not to do it that way as then we can't put it under source control).

Actine commented 10 years ago

Unfortunately I have no experience with Jaspersoft Studio but I believe there has to be a way to add input controls to the report directly - please refer to JSS guides or such. From functionality point of view, you may create input controls as private ('inner') for a report, or refer to 'external' input controls stored in repository as separate resources.

And yeah, what you have been appending to report's URL was in fact input control values too. The terminology may be confusing here. Think of the array you pass to PHP client as an assoc array of parameter_name => array_of_values.

joshabts commented 10 years ago

If that is the case, then what I was passing via my code should have worked, shouldn't it?

On Fri, Jul 4, 2014 at 11:05 AM, Actine notifications@github.com wrote:

Unfortunately I have no experience with Jaspersoft Studio but I believe there has to be a way to add input controls to the report directly - please refer to JSS guides or such. From functionality point of view, you may create input controls as private ('inner') for a report, or refer to 'external' input controls stored in repository as separate resources.

And yeah, what you have been appending to report's URL was in fact input control values too. The terminology may be confusing here. Think of the array you pass to PHP client as an assoc array of parameter_name => array_of_values.

— Reply to this email directly or view it on GitHub https://github.com/Jaspersoft/jrs-rest-php-client/issues/11#issuecomment-48053463 .

Actine commented 10 years ago

If your report has an input control with id user_id matching the parameter in your query, then it should have.

joshabts commented 10 years ago

Ok I will attempt that and look into adding input controls directly in the reports. Thanks!