Jasper report expression evaluation - jasper-reports

I have a report that evaluates values and checks if the conditions are correct, if yes it is a success and the report returns Pass
However the equation needs to be modified
Current equation is
($F{SPECPASS}.equals($F{SPECS}) ? "Pass" : "Fail")
I want the new equation to be something like this
If SPECPASS/SPECS >=0.5, then STATUS = ‘Pass’, Otherwise STATUS = ‘Fail’
I am new to Jasper reports and the version we have is 3.6.0
Thank You

I think, we can use
(($F{SPECPASS}.doubleValue() / $F{SPECS}.doubleValue() >=0.5) ?"Pass":"Fail")

Related

Invalid Name Error - Crystal Reports in VB6

I'm trying to set the title of a crystal report in VB6, but I keep being shown an error.
The parameter field that I want to set the text of is called txtTitle.
However, when running this code, it gives an error saying
Invalid Name
If opt_sales_ledger.Value = True Then
crxReport.ParameterFields.GetItemByName("txtTitle").AddCurrentValue ("List of Sales Ledger Accounts")
ElseIf opt_purchase_ledger.Value = True Then
crxReport.ParameterFields.GetItemByName("txtTitle").AddCurrentValue ("List of Purchase Ledger Accounts")
End If
What's causing the error?
Crystal is looking for a "parameter" type field called "txtTitle" and it cannot locate it. I usually use formulas for this purpose, in other words "txtTitle" would be a formula in the report and defined and/or initialized as a stringVar
Try to use this way:
crxReport.ParameterFields(1).AddCurrentValue ("your_first_parameter_value")
crxReport.ParameterFields(2).AddCurrentValue ("your_second_parameter_value")
Good luck!

INSTR in Crystal

We are using this function to filter data by program codes entered, if nothing is entered return all?
Can any one please explain this Crystal function, and how Crystal works with it? Mainly the last statement.
Here is some information that might be useful.
{?Program} ==> Parameter to accept different programs codes in the following form
303&410&110
{Command.program_code} ==> Field were program code is stored
if ({?Program} = "")
then true
else
(INSTR("&" & {?Program} &"&", "&"& {Command.program_code} & "&")>0)
Thanks...

iReport/JasperReports Server: Subreport return value null

I have the following problem with iReport / JasperReports server.
I'm using a main reports with two subreports returning a calculated price, the type of the subreport variable and the local variable is BigDecimal.
If the return value from a subreport is null (no rows found) then the assigned local variable in the main report is always null. But I want to have "0.00" because I want to calculate a sum.
The construct (return_variable == null ? new BigDecimal(0) : return_variable) doesn't help as well as to set the local variable to a default value new BigDecimal(0). I always get null instead of the wanted value "0.00" ;-(
I've tested with version 3.7.6 until 4.4. of iReport, nothing helps.
Does anybody have a hint for me? Thank you in advance.
I've had the same problem, except I tried to use the return value of the subreport as a parameter of another subreport. I succeeded in getting the result I wanted by using a scriptlet in the second subreport.
I proceeded this way :
-in subreport 2, I have my parameter p (Float), its value being the return value of subreport 1
-in subreport 2, I have a variable v (Float), initialized with p
-in my scriptlet (in the method beforeDetailEval(), I test my variable v : if it is null, I assign the value new Float("0.0")
I works ok.
The limitation with this is if you want to use the return value of your subreport directly in your main report. I tried doing that, but never succeeded.
Hope this will help someone some day.
Cecilka
Yahoo! By the Grace of GOD, I found a great answer to my own question. Posting it as it may help someone in future.
1) I changed my Simple SQL Query with a MySQL stored procedure as.
My Stored Procedure as
BEGIN
SET #p = 0;
SET #n = 0;
SET #m = '00';
SELECT x.*, y.* FROM
(select #n:=#n+1 as "ID", #m:=acc as "Account" from tbl_reports) x
right JOIN
(SELECT if(#m='00',0,#p:=#p+1) as "IDU") y
ON y.IDU = x.ID;
END
In IReport, I declared my variable as
$F{IDU}>0?$F{Amount}:0
In this way, it now shows 0.00 instead of null.

Database-field with false as value sent over XSD to Crystal Reports is evaluated as true

The application I work on is using a Crystal Reports to present reports to the user. I am using Visual 2010, but the report was created by a previous employee some years back using Visual2005.
The basic setup is that the client application make a request to the server that uses a xsd that define the data-set it sends back. Generally this work like expected, but I am having some problems with evaluating booleans.
A recent task consider of adding the dataset with a field name TrueWeekday that control if certain numbers should be printed out or not depending on if a date is a regular weekday or have some special local meaning that might affect the sampled data. The data is always used in some formulas so I can not exclude it from the dataset.
My first attempt involved defining the new field as a boolean and in the formula for the report I wrote
if {Header.TrueWeekday} then
CStr({Detail.Flow})
else
""
This had the result that no matter if the value in TrueWeekday was false or true the flow was presented. I debuged the server to verify that the variable indeed got the expected value so the problem happened in the Crystal Reports or in the transfer of data to Crystal Reports.
To solve this particular problem within the timeconstraints of the task I changed the field to the type string and wrote
if {Header.TrueWeekday} = "false" then
CStr({Detail.Flow})
else
""
This worked like a charm.
My problem here is not urgent since I have a working solution, but I am worried that this problem might create more subtle dataintrigity problems.
What might be the cause of this and how do I solve it?
Header.TrueWeekday is probably being passed as a string so that when you do if {Header.TrueWeekday} its testing a string as a boolean in which case if the string contains anything it evaluates to true and thus causes your problem
Work in a different project made me realize that .Net is probably serializing the boolean as the text string true/false. If then Crystal Reports does sloppy import and only check
input != 0
you will get the result that both true and false map to true after the transfer.

Crystal reports 11 : blank field bombs the report

I'm creating a invoice crystal report for sage mas 500 AR module. In it, I'm attempting to add the tarinvoice.balance field with the following formula:
if {tarPrintInvcHdrWrk.Posted} = 1 then
ToText({tarInvoice.Balance})
I'm assuming that when the {tarPrintInvcHdrWrk.Posted} = 1 conditional statement holds FALSE, it doesn't attempt to pull the invoice field because when I remove the formula from the report, the form displays correctly without it.
When the conditional statement renders true in the report, the balance fields behaves correctly. However, with the formula renders FALSE in the CR form, the entire crystal report bombs and displays blank. Any ideas why or what I'm doing wrong?
Just tried setting everything to zero and the report still bombs. I'm starting to think its more of a query error in the report. I wish there was a way to exclude the field in the query when posted = 0.
With tarinvoice.balance removed when the posted = 0, the report works fine.
With tarinvoice.balance included and posted = 1, report works fine.
With tarinvoice.balance included and posted =0, report bombs.
I believe the conditional statement fails immediately if you encounter a NULL, so your formula needs to test IsNull({tarPrintInvcHdrWrk.Posted}) before it tests equality with "1".
You can change the way Crystal handles a null value for a value in a formula. At the top of the Formula Workshop there is a drop down box that usually says "Exceptions For Nulls".
Change this to the other option "Default Values For Nulls" and your formula should no longer bomb out. You used to be able to specify the what the default values applied were, but more recent versions of Crystal have these hard coded.
Search the help for "Null Treatment" for a table showing them.
I modified the formula to this:
if isnull({tarPrintInvcHdrWrk.Posted}) = FALSE then
if {tarPrintInvcHdrWrk.Posted} = 1 then
if isnull({tarInvoice.Balance}) = FALSE then
ToText({tarInvoice.Balance})
else
"0.00"
else
"0.0"
else
"0"
The crystal report still bombs.. Nevertheless, it does show "0" in the appropriate space.
I saw a suggestion on Exp.Exch to try putting the field into a variable before converting it to text.
e.g.
NumberVar InvoiceBalance;
If isnull({tarInvoice.Balance}) then
InvoiceBalance := 0
Else
InvoiceBalance := {tarInvoice.Balance};
If {tarPrintInvcHdrWrk.Posted} = 1 then
ToText(InvoiceBalance);
I also tried to recreate your problem, since I have see similar things before.
No luck though trying with CR 8.5 & XI R2. Perhpas it has to do with linked tables as well, since I only tried on a simple single table.
I have also seen similar behaviour when using a formula within a Running Total - they do not like nulls at all!
If you put {tarInvoice.Balance} directly on report (into details "debug" section - often needed, don't forget supress it in production :)), what values it displays or does report become empty?
Maybe you have Suppress If Blank section on your report. Try to put: Else " "
if isnull({tarPrintInvcHdrWrk.Posted}) or {tarPrintInvcHdrWrk.Posted}=0 then
" "
else
if {tarPrintInvcHdrWrk.Posted} = 1 then
ToText({tarInvoice.Balance})
else
" "
I have trouble with this kind of field when making reports to export to excel. A field with no data in will pull all columns to the right of it over to "fill the gap".