Issue with passing field variable to subreport from master report - jasper-reports

I am trying to do a simple expression in iReport, but whatever I try seems hasn't given me which I expected. It seems like such a simple thing to do, but I couldn't understand what's happening with my code.
All I'm trying to do is show a subreport when the value of an string field is a simple word like "VALUE". I am using the Print When Expression for the subreport control, however I'm not able to the see or reproduce this text with this expression. For me seems that I'm not passing well the parameters I wan't to use to do the print when expression in the subreport from the master report.
Is a disclaimer, so in master report I have a simple subreport, with the same conection from master and one parameter called Entity = "_id.Entity" (we use mongodb to get the fields for the report with a $group) and in the subreport part I have 2 text fields, the first one have the print when expression when P{Entity}.equals("VALUE"), the second one don't have any condition so this works perfectly, but the textfield with the condition doesn't work.
Any help would be appreciated. Thanks.

Related

Crystal Reports Selection Formula If No Match Then

I currently have a Crystal Report with a selection formula that looks like this
{dbo.CustomerName}={?CustomerName}
AND
{dbo.Opportunity}={?Opportunity}
An issue that I'm finding is that sometimes there isn't a matching customer name, but the report still needs ran on the subsequent selection formula. Is there a way to create an IF THEN statement that says something like:
IF IsNull({dbo.CustomerName}={?CustomerName})
THEN
{dbo.Opportunity}={?Opportunity}
ELSE
({dbo.CustomerName}={?CustomerName} AND {dbo.Opportunity}={?Opportunity})
Obviously the IsNull operator requires a field and not a statement, but I'm not sure how to accomplish what I'm trying to accomplish
The following should work:
(IsNull({dbo.CustomerName}) AND {dbo.Opportunity}={?Opportunity})
OR
({dbo.CustomerName}={?CustomerName} AND {dbo.Opportunity}={?Opportunity})

Round up double value in jasper report

I have a textfield in jasper report as follows :
<textFieldExpression class="java.lang.Double"><![CDATA[$V{v_vcTotal}]]></textFieldExpression>
I want to round up this value using HALF_UP rounding mode.Can i achieve this in a simple way.Thanks in advance.
EDIT : I dont want to change my java class. Is there anything i can do in jasper jrxml file.
So all credit to #utkarsh their expression is so far the only working one I've seen online that converted my 'double' numbers pulled onto my report, my expression:
$f{balance}
Would produce doubles from a calculated field in my database like "-1365.00000000003"
In the Expression editor (in lieu of changing it in the source tab) I wanted to pull 2 sig figs from the number for looks. I added this expression and I stopped getting "compilation" errors and the wanted results:
new BigDecimal($F{balance}).setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()
Result would be "-1365.00"
From what I've read this is a bit overkill to get the desired result but I am also under a deadline so I will try to optimize some other time.

Subreports dependancy

Is there a way to show one subreport if the other subreport doesn't have any rows (doesn't return any rows).
What have I tried:
In my first subreport I returned the number of processed rows "REPORT_COUNT" to master report variable "SUBREPORT_VAR". Variable "SUBREPORT_VAR" works as it should. I added additional text field to master report and output variable to it. I set Evaluation time of text field to Band, as without this it doesn't work correctly.
Further I set option "Print When Expression" of the second subreport to:
$V{SUBBREPORT_VAR} < 1
I use jasper studio 5.5.0 final.
If there is no row count wouldn't the result be null.
If so you you could use this in the print when expression in your second subreport:
$V{SUBBREPORT_VAR}==null
another option is to run the query in your main report and use this as the subreport expression:
IF($F{SOME_VAR_FROM_YOUR_QUERY}==null,subreport2.jasper,subreport1.jasper
This prints subreport2 when your SOME_VAR_FROM_YOUR_QUERY returns null if not it prints subreport1.

Deploying subreports in JasperServer

I have created a frame and subreport for integration with APEX and refined to the point I am ready to deploy on JasperServer. Somehow the exact syntax is defeating me. I've tried all the variations the following questions would indicate, but nothing seems to work. I'm using Glassfish, btw, but I don't think that is significant. Here are my questions:
When deploying the subreport, do I deploy as a report or as a JRXML file?
Do I need to set up Input Controls for the subreport, as passed by the frame report?
Does it matter where I deploy the subreport (folder structure) so long as I am passing the correct SUBREPORT_DIR parameter to the frame?
On that SUBREPORT_DIR, I've tried a couple different things. First I had the default as an absolute path on my local box, for debugging purposes, and was passing the value I wanted in the URL (i.e. ...&SUBREPORT_DIR=/Subreports/...). I also tried setting the default to the path I wanted. Neither works, but should the former work as well as the latter?
What's the actual syntax for passing SUBREPORT_DIR? I've deployed my frame report as "/reports/frame" and my subreport as "/reports/Subreports/sub", so I was passing "repo:/Subreports/" (without quotes in the URL, with quotes in the default on frame).
My frame and sub work in iReport with the same params I'm passing, but they don't work from the URL at all. I can load up the sub as a report under JasperServer, pass it the params frame passes, and get it to work, but when I try to run the frame, no dice.
Thanks in advance for all the help, and I hope to pay it back once I get this properly configured.
OP's findings.
The subreport needs to be deployed in the repository as a JRXML file. It will say "File" in the appropriate column of the repository view.
You do NOT need to set Input Controls for the subreport. The frame report needs only those Input Controls that it utilizes, not the subreport parameters.
As long as you pass the correct SUBREPORT_DIR, you can put the subreport anywhere you want, but remember that the frame report will reference the sub by exactly the name you specify. One of my two problems (see #1 above for the other) was specifying an extension in the default path. This was correct in iReport, but wrong on the server side.
SUBREPORT_DIR can be passed as a parameter and works as advertised.
The correct path for SUB_REPORT_DIR, which I am using now as a defaulted param, is something like "repo:/reports/Subreports/". The Subreport Expression under detail is therefore: $P{SUBREPORT_DIR} + "five_col_sub". See #3 above.
Not that tricky, really, but also not completely intuitive. My colleague pointed out that "repo: " is short for the JasperServer Repository. Seems obvious now, but I was assuming it meant "reports", necessitating that any report with a subreport and the subreport itself would have to exist under the /reports/ directory, which is not the case.

'This field name is not known' error (Crystal Reports)

Here is a strange problem I have run into.
My record select formula is as follows, I have dumbed it down for purposes of this error:
reportDocument.RecordSelectionFormula = " {#ClientName} = 'Smith' "
If I copy this exact selection statement into Crystal it previews fine, but when run from .NET I get
'This field name is not known'.
The problem is occurring at the #ClientName formula field.
#ClientName simply contains:
formula = {aw_illust.CL1LNAM}
I can also set it to just a blank string (formula = "") and it still gives
'This field name is not known.'
Here is the strange part, if I bypass the formula and put the formula text straight into .NET everything works fine.
reportDocument.RecordSelectionFormula = " {aw_illust.CL1LNAM} = 'Smith' "
That is the same record selection, except with the '#ClientName' formula replaced with '{aw_illust.CL1LNAM}'. It just happens on this one report, I have many other Crystal Reports working with formulas referenced in .NET just fine. Any ideas?
Most likely you are not using your {#ClientName} formula anywhere on report; Crystal Reports tends to ignore unused fields, formulas etc. Place {#ClientName} field somewhere in report (header or some similar section) and suppress it - this way you don't mess up report design, but CR should know about that formula afterwards.
Which syntax has the formula? If it is crystal syntax then change it to basic syntax. Or change the content of the formula to crystal syntax (without "formula =")
You could create a parameter like {?ClientName} and set that from .NET, and then put a select formula in Crystal like {#ClientName} = {?ClientName}.
Can you save the report with the selection criteria you'd like then display what the reportDocument class sees using something like:
TextBox1.text = reportDocument.RecordSelectionFormula
This would confirm that your syntax is correct.
Same happened with me when I copied existing report to be used as the new one, You can first open report in report viewer ,In my case
but the query that loading report has no selection with name DateLocal Transaction so I got this error, the resolve is to either use only those that are require (Extras has nothing to do with the error) or rename selection value in query.