I have 100,000 account numbers. I want to randomly give any 5 (as per my requirement. Could be 1 or 2 or 20) account numbers and see the information about them.I have tried the following.
I tried with string input control, cascading input control with one string and one list parameters. But none of them works.
1) String Input Control: I tried entering the 3 random account numbers comma separated. But my query dosent accept the same since I have to use a list parameter and $X variable.
($X{IN,acct_no,test}).
2) Cascading Input Control: I thought let me take a string input control and a list list input control and use the string input control within the list input control. So I tried like the following.
Created a parameter and an input control with string datatype (where I can enter comma separated account numbers). The parameter name is $P{account_no}
Created a list parameter and an input control with list datatype as an multiselect query using the string parameter as below. The parameter name is $P{test}
select account_no from customers where account_no IN ($P{account_no})
Note that I have used the first parameter.
This works fine for only 1 account number and not for 'n' account numbers.
I also tried something like
select account_no from customers where ($X{IN,acct_no,account_no})
For obvious reasons this does not work.
I am using Jasper 5.0.1
Is there a way to dynamically populate a list based on the input values.
Could anyone kindly let me know how to achieve my desired output?
Any help would be appreciated.
Many Thanks.
The following did the trick.
SELECT customer_name FROM customers where account_no in($P!{account_no});
Related
I have some samples I need to take.
In order to create a good identifier/serial number for the samples, I want it to be a product of its characteristics.
For example, if the sample was taken from India and the temperature was 40 degrees then I would click dropdowns in the form to create those two entries and then a serial number would be spat out in the form "Ind40".
Assuming that your form is bound to a table, you can create a calculated column in the table that concatenates the values from other columns into a single value.
For instance, create a new column and give it a name (for example, SerialNbr). Then for Data Type select "Calculated". An expression builder window will appear:
Enter the columns you'd like to concatenate and separate them with &. Here is an example of how the expression could look:
Left([Country],3) & [Temperature]
This expression takes the first 3 chars from the Country column and combines it with the value from Temperature column to create the value in column SerialNbr. The calculated column will automatically update when values are entered into the other fields. I'd also suggest adding another value to the calculated expression to help avoid duplicates, such as date/time of submission.
For example, I show two columns--CustNumber and CustName. In a filter, I would like to concatenate the two values something like this:
10100 My Customer
This would allow the user to enter either the customer number OR some of the customer's name in drop-down filter to filter by.
Thank you.
You would need to create a separate calculated field to use as the filter.
CustNumberName =
STR([CustNumber]) + ' ' + [CustName]
CustNumberName can then be used as a filter (presumably set to Wildcard Match) and the existing 2 columns can stay in the pane.
You can create a calculated field as G Hart states.
You can also create a combined field, by selecting multiple dimensions in the data pane and right clicking to Create->Combined Field. The combined field behaves very similar to a calculated field in most respects and you can easily change the delimiter or field order.
There are a few restrictions with combined fields. They can’t be used in most (or all?) calculations, nor to populate the list of possible values for a parameter. But they are easy and convenient otherwise.
I'm creating a demographics report where users can choose what demographics they want to include on the report. One of the options is age range where the user can type in their own figures. Everything works except when the age range parameters are not used. The others can be blank as they are string types but the age range parameters are number types because I need to use them to do counting. Is there a way to use number type parameters but allow them to be blank if necessary?
I tried changing the type to string and then running a ToNumber formula to use the field for my needs but I get the same error. I also tried suppressing any fields that use number parameters but trying to say suppress is Not HasValue but that didn't work either.
In my main report I get a (small) list of string values from the data base. I then want to use this list for selecting records in a subreport, along with other input parameters:
The user shall be able to select records based on a range of begin and end date -- this is easy using an input parameter of type java.util.Date with "Is For Prompting" set to true. Another criteria shall be one or more items from a list showing values from a data base field. I could define the list in the report template, but then I'd have hard-coded strings (filled from the data base, but at definition time only).
Now the dilemma is: If I define the input parameters in the main report, I cannot get the values for the list beforehand; if I define them in the subreport, I get no prompt at all, so there's no way to set any of them.
So the report requires values for start and end date, and a list of string values to select from (multiple itmes can be selected). This list shall be built from values from the data base. In the subreport all these values shall be joined into a filter for the records. A user shall be able to define the dates and select items from the list manually before executing the report.
Is there a way to achieve this?
After some more hours of trial & error, and some more research, of course, I found that the keyword is "Query-based Input Controls". This documentation describes their creation on the JasperReports Server. Such input controls can be edited in Jaspersoft Studio as well, however, they actually work on the server only. Anyway, this is the solution to my problem.
I have a report with multiple data-sets. Different fields from different data-sets are used in different locations of the report.
In one part of the report, I need to do a calculation using fields from two different data-sets. Is this possible within an expression?
Can I somehow reference the data-set the field is in, in the expression?
For example, I'd like to do something like this:
=Fields.Dataset1.Field / Fields.Dataset2.Field
You can achieve that by specifying the scope of you fields like this:
=First(Fields!fieldName_A.Value, "Dataset1") / First(Fields!fieldName_B.Value, "Dataset2")
Assuming A is 10 and B is 2 and they are of type numeric then you will have the result of 5 when the report renders.
When you are in the expression builder you can choose the Category: Datasets, your desired dataset highlighted under Item: and then double click the desired field under Value: and it will appear in your expression string with the scope added.
Using same logic you can concatenate two fields like so:
=First(Fields!fieldName_A.Value, "Dataset1") & “ “ & First(Fields!fieldName_B.Value, "Dataset2")
As PerPlexSystem writes, asuming you only want to compare the first value from a dataset with values from another dataset, you can use the First function.
However, if you want to compare the values of each row from one dataset with with the values from each row of another dataset, then you will need to use a subreport - see here for further details.
Another option is to use a parameter as a variable. This is helpful if you want to create a calculated field in one of the datasets. This is best applied when the parameter value comes from a dataset with a single record.