Use value returned from main dataset in sub dataset of iReport - jasper-reports

I have created a report with Jaspersoft Studio 6.4.3.final which contains List Element. I need to use value returned from main dataset in sub dataset (List Element) query.
Main data set return something like below. (always only one record return)
CustomerName JobID
John 123,146
I need to use JobID in sub dataset (List Element) query as below.
Select * from JOB where jobId in (123,146)
I need to use the 123,146 form value returned from main dataset.
How could I achieve this?
What I have tried
I have created a parameter in sub report as below.
Then bound the relevant field from main report to the sub report parameter as below.
Updated the sub dataset query as
Select * from JOB where $X{IN,jobId,p_jobId}
With these changes, I am getting below exception.
Invalid type java.lang.String for parameter p_jobId used in an IN
clause; the value must be an array or a collection.

You can pass the value returned from the main dataset as a parameter to the List element and use it in the subdataset.
If it's a multi value parameter, you can use the $X notation in the subdataset query.
So your query could look something like this:
Select * from JOB where $X{IN, jobId, MyParam}
Where MyParam is the subdataset parameter name.

Related

Reference a Main_Dataset in a subDataset

I want to reference my MAIN dataset in a Jasper .jrxml when querying for my subdatasets.
I have about a dozen sub-datasets that all rely on the main set, in the following way:
SELECT
what_i_need,
for_my,
subdataset
FROM
(my main dataset which has a fairly long query) m
group by m.sth
order by 3,4 desc, 2;
What that does is query the main and then use that as a table to query for the subs, but the drawback is that I have to change every subdataset manually every time I need to change the main
I'm aware that I COULD go for creating a view in the database and then simply referencing that from inside Jasper for both main and subs.
(And also changing the view definition as needed)
I'm asking whether Jasper can be "taught" how to use the entire main dataset as a parameter for the subdatasets?
The goal is to set all the subdatasets once with some sort of parameter, and only change the main, and have the expected results.
The end goal should be something like this:
SELECT
what_i_need,
for_my,
subdataset
FROM
$P{Main_Dataset} m
group by m.sth
order by 3,4 desc, 2;
Add String parameter to your dataset, let's say pQuery.
SELECT ...
FROM ( $P!{pQuery} ) m
GROUP BY ...
ORDER BY ...
Exclamation ! char is important.
In chart's datasource:
Use connection expression with default value $P{REPORT_CONNECTION}.
Add pQuery parameter and set expression as $P{JASPER_REPORT}.getQuery().getText()

Why no output from Talend tMSSqlSP or tMSSqlRow

I am not new to ETL and trying to become familiar with Talend. I cannot seem to get any output of a stored procedure (using tMSSqlSP) or a query (using tMSSqlRow). NOTE: Things I read indicated that tMSSqlRow doesn't produce columnar output but not sure that is correct.
The job shown below runs but no output comes from the tMSSqlSP component. The trace debug shows that the output title is null. However, manual execution of the SP in SSMS succeeds, showing both objid and title.
The SP performs a simple query accepting a single input parameter (int) and outputs two columns -- the objid (int) and the title (string):
create procedure st_sp_case_title_get
#objid int
as
select [objid], [title] from [dbo].[table_case] where [objid] = #objid
You need to use tParseRecordSet in order to retrieve and parse result sets from tMSSqlRow and tMSSqlSP :
Define a column to be your result set (mine is called result) of type Object, in addition to your input columns (my input param is personid). In tMSSqlSP parameters tab, set personid as type IN, and result to be of type RECORD SET.
tParseRecordSet schema :
It parses the result column and gets Firstname and Lastname columns (your objid, and title columns)
tMSSqlRow is very similar. Check my previous answer here for an example.

Unable to dynamically change value for static label column header

I am unable to dynamically change the column header values during run time while creating a jasper report. Why do I keep getting string to boolean cast exception everytime I assign the value to table element's column header??
I have a column header that is a part of the table element. And this table and its dataset are not a part of the main data set. I want to the column header to change dynamically based on values in the main dataset. The main dataset and sub data set return different resultsets
The steps I followed were:
create a variable called v1_enabed (string) and v1_display(string) in the main dataset. I also assigned the required fields(from the main data set) to these variables
I created a parameter p1(string) in subdataset
I use the subdataset fields for table creation. I used the table element.
I go the table and map the parameter p1(string) to the table. And I assign the expression ($V{v1_enabled} == Character.toString('1')) ? $V{v1_display} : $V{v1_display} to it
Until here whenever I run the report, I do not get any error.
Now, I go the table. Pick up the 5th column and assign this in the print when expression section -- $P(p1)
Now, comes the error: java.lang.String cannot be cast to java.lang.Boolean
How do I solve this?

SSRS: Call a dataset from a textbox with a parameter

I have a dataset that is a query which has a where clause like this 'where field1 like #parameter1' parameter1 is a string defined as a parameter in the dataset1. I have various text boxes that calls the dataset with expressions like =First(Fields!field_xx, "Dataset1"). For each textbox I like to specify a different value for #parameter1 when it calls the "dataset1". How can I modify the expression in each textbox as to call the "dataset1" from each of them with a hardcoded value for #parameter1
the query:
SELECT TOP (1) job.job_id, job.originating_server, job.name, job.enabled, job.description, job.start_step_id, job.category_id, job.owner_sid, job.notify_level_eventlog,
job.notify_level_email, job.notify_level_netsend, job.notify_level_page, job.notify_email_operator_id, job.notify_netsend_operator_id, job.notify_page_operator_id,
job.delete_level, job.date_created, job.date_modified, job.version_number, job.originating_server_id, job.master_server, activity.session_id, activity.job_id AS Expr1,
activity.run_requested_date, activity.run_requested_source, activity.queued_date, activity.start_execution_date, activity.last_executed_step_id,
activity.last_executed_step_date, activity.stop_execution_date, activity.job_history_id, activity.next_scheduled_run_date, steps.step_name
FROM sysjobs_view AS job INNER JOIN
sysjobactivity AS activity ON job.job_id = activity.job_id INNER JOIN
sysjobsteps AS steps ON activity.last_executed_step_id = steps.step_id AND activity.job_id = steps.job_id
WHERE (job.name LIKE 'Actual Job Name')
ORDER BY activity.start_execution_date DESC
It is not possible to call a dataset with different parameters in the same report execution. Every execution and rendering of the report fetches each dataset only once.
This means that you have to construct your dataset in a way so that it returns all the data you need, to populate each of your textboxes.
Depending on your data model, you may want to add more columns to your dataset, or return the data in multiple rows. If you have multiple rows, then you can use the Lookup function in an expression, to filter out the row in each individual textbox.
Perhaps if you elaborated a little more on what your report should look like, and what the structure of the data you are fetching is, it would be possible to give a better answer to how to solve your problem with a single dataset.

The default expression for the query parameter contains an error

I have a dataset referencing a proc. That proc takes in a #UserName
In my parameters of my dataset, I have specified a new param called #UserName and for its default value the expression =User!UserID but I still get this error when the report tires to render:
The default value expression for the query parameter #UserName contains an error [BC30654] 'Return' statement in a function, Get, or Operator must return a value
The only thing I can think of is that instead of modifying the existing datasource I had defined in the report, I removed and added a new datasource. I hope that doesn't matter as long as there is a valid data source for the report to go on that has those fields...I just switched this report to reference a copy of our current database for testing purposes.
Sounds like the report parameter is not being passed to the stored procedure.
In the Dataset Properties, click on the Parameters tab and check that the stored proc parameter #Username is correctly mapped to the Report parameter #Username.