PAGE_COUNT not rendered correctly in JasperReports...? - jasper-reports

I have added the footer Page x of y to my report, but the PAGE_COUNT doesn't seem to work.
Maybe the problem occurs because I have many subreports?
I get:
Page 1 of 1
Page 2 of 0
Page 3 of 0
Page 4 of 0
Any ideas?

Well, don't know elder versions but in JasperReports 4.5.1; you can define two text fields both includes $V{PAGE_NUMBER} variables. The one which has EvaluationTime: now shows current page number; the other one with EvaluationTime: report shows the number of total pages. A simple trick but works :)

Changing the evaluationTime="Report" solved the problem.

Summary: To have the page number and the page number in a TextField.
Step 1: Create a variable that indicates the number of the current page.
     Settings:
* Name: CURRENT_PAGE_NUMBER
Variable class: Java.lang.Integer
Calculation: nothing
Reset Type: None
Increment type: Page
Variable Expression: $ V {CURRENT_PAGE_NUMBER} == null? $ V {PAGE_NUMBER}: $ V {PAGE_NUMBER} +1
Step 2: TextField Settings
Text Field Expression: "PAGE:" + $ V {CURRENT_PAGE_NUMBER} + "/" + $ V {PAGE_NUMBER}
Expression class: Java.lang.String
Evaluation Time: Auto
And that's all. No need to add anything to it to give you a result like: Page 1/3 | Page 2/3 | Page 3/3.

I found the solution.
http://jasperforge.org/tracker/index.php?func=detail&aid=2873&group_id=102&atid=612
But the book JasperReports for Java Developers (p 146) says that PAGE_COUNT is the total number of pages in the report. I guess the bug is in the book.

Actually It Is a BUG! And confirmed by developers.
See link:
jasper community bug tracker link
PAGE_COUNT is not correctly calculated, when using property on BAND: "Split Prevent"

our reports look like :
http://pastebin.com/m401fa41
1st part, interpreted during page generation, gives the # of the current page (evaluationTime="Now")
2nd part, interpreted at the end of the report , gives the total # of pages (evaluationTime="Report")
HTH

The solution is the follow :
We must not put $ { V PAGE_NUMBER }+ "/" + $ { V } PAGE_NUMBER in the same field.
the proper way is to put $ { V PAGE_NUMBER } in separated field and "/ " + $ { V } PAGE_NUMBER in the other field
it work for me
sorry for my english

I haven't access to the jaspercommunity (to check the link shared), but I do a good workaround :D
Use 4 texts, like this:
txtStatic1(Page) txtField1($V{PAGE_NUMBER}) txtStatic2(of) txtField2($V{PAGE_NUMBER})
Where:
txtField1($V{PAGE_NUMBER}) -> AVAILABLE TIME = PAGE
txtField2($V{PAGE_NUMBER}) -> AVAILABLE TIME = REPORT
It's works to me.

Related

Issue networkdays value in google spreadsheet

I have created the formula = NETWORKDAYS.INTL(E84,F84) and E84 and F84 are same date -> 2022.9.5. if it is the same date in both columns, it shows the value 1 but it shows the value 0.
It worked before but now it doesn't work.
https://docs.google.com/spreadsheets/d/1dY6gwDIjjxUPTU-4v0j1MqF1sq7YCgHLTH040QMQrHU/edit?usp=sharing
There was an issue and now it's working properly. Here are more details.
If you refresh the document, you can reload the function with the fix.
looks like a bug but here is some quick workaround:
=IF(A2=B2; 1; NETWORKDAYS(A2; B2))

How to reach the end of a chain of cells

I have a file with two sheets:
sheet_A
A B
1 Mr. Joe USD
sheet_B
A B
1 =sheet_A.A1 ???
sheet_B.B1 shall show the value USD. I know i could get it easily with =sheet_A.B1 but I do not want that.
If I enter into sheet_B.B1 =ADDRESS(ROW();COLUMN()-1) I get the output $C$1 and with =INDIRECT(ADDRESS(ROW();COLUMN()-1)) Mr. Joe.
How can I "navigate" through a chain sheet_B.B1 - sheet_B.A1 - sheet_A.A1 - sheet_A.B1?
Edit 1
Maybe I need something like this
=OFFSET(FORMULA(ADDRESS(ROW();COLUMN()-1);0;1)#
sheet_B.B2 shall show the content of sheet_A.B2 in relation of the value in sheet_B.A1
Here are two possibilities. Either formula produces USD in sheet_B.B1.
=INDIRECT(ADDRESS(ROW();COLUMN();;;"sheet_A"))
=VLOOKUP(A1;$sheet_A.A1:B1;2)
Documentation: ADDRESS, VLOOKUP.
EDIT:
One more idea: The following produces the string "=sheet_A.A1", which could be parsed for the sheet name and cell address. Perhaps you would like to use it to refer to sheet_A.B1.
=FORMULA(INDIRECT(ADDRESS(ROW();COLUMN()-1)))
However, as I commented, there is probably an easier way for what you are trying to accomplish.
Documentation: FORMULA.
EDIT 2:
Here is the formula you requested. It uses REPLACE to remove = at the beginning of the string.
=OFFSET(INDIRECT(REPLACE(FORMULA(INDIRECT(ADDRESS(ROW();COLUMN()-1)));1;1;""));0;1)

Crystal Reports incorrectly printing duplicate data

I am modifying a subreport that prints optional report card comments. The data that is supplied (via a stored procedure) is in this format (trimmed for brevity):
StudentID / Grade / CourseNum / ReportCode / CName / Comment
9999991 / KG / EA0_AM1 / M1 / T1Comment / Pam is good!
9999991 / KG / KP0_PM1 / M1 / T1Comment / Pam is okay!
9999992 / 3 / EA3_AM1 / M1 / T1Comment / Joe is good!
9999993 / 5 / EA5_AM1 / M1 / T1Comment / <null>
If a student is not in kindergarten, the only comment I want to print is the one where CourseNum = "EA?_AM1". If they're in Kindergarten, however, the comments should pull from "EA0_AM1", "EA0_PM1", "KP0_AM1", and "KP0_PM1", and those comments should be concatenated. The original report would only print the comment from either "EA0_AM1" or "EA0_PM1", but not both (it didn't know about the other two kindergarten classes, and it used a running total to find the maximum value for Comment), but among the four potential classes there are two potential teachers, and this year they both want their comments to appear on the report card. I don't think it matters, but here's the record selection formula:
(Select {?Marking Period}
Case '1' : {ReportCode} = 'M1'
Case '2' : {ReportCode} in ['M1', 'M2']
Case '3' : {ReportCode} in ['M1', 'M2', 'M3']) and
(Select {Grade}
Case 'KG': {CourseNum} in ["EA0_AM1", "EA0_PM1", "KP0_AM1", "KP0_PM1"]
Default : {CourseNum} like "EA?_AM1")
({?MarkingPeriod} refers to the trimester we're interested in.)
The problem I'm encountering springs from the fact that we want to print T1, T2 and T3 comments separately. I found the start of my solution in an answer given by Abhilash Kumar in a thread here: http://scn.sap.com/thread/3195910. Based on his answer to someone else's question I created a formula GetAllCommentsT1:
WhilePrintingRecords;
stringvar array arrT1;
numbervar iT1;
if not(({Comment} in arrT1) and ({CName} like "T1*")) then
(
iT1 := iT1 + 1;
redim preserve arrT1[iT1];
arrT1[iT1] := {Comment};
);
arrT1[iT1]
GetAllCommentsT2 and GetAllCommentsT3 are identical except that all instances of "T1" are replaced with "T2" and "T3" respectively. I placed these three formulas in the Details section (this section is suppressed: only Group Footer 2a through 2d are enabled).
To display the results, I created three formulas (DisplayT1Comments, DisplayT2Comments, and DisplayT3Comments). All are similar to this:
WhilePrintingRecords;
stringvar array arrT1;
join (arrT1, CHR(13) + CHR(13))
with "T1" replaced with "T2" or "T3" as appropriate. DisplayT1Comments is placed in Group Footer 2b, DisplayT2Comments is placed in Group Footer 2c, and DisplayT3Comments is placed in Group Footer 2d.
Using the data mentioned at the beginning of this question, for StudentID: 999991 DisplayT1Comments is "Pam is good!\n\nPam is okay!", and that's exactly what prints in Group Footer 2b. Since no T2 or T3 comments have been entered yet (verified directly in the database), I would expect both DisplayT2Comments and DisplayT3Comments to be null. However, when I run the subreport the contents all three footers are displaying "Pam is good!\n\nPam is okay!"
Any ideas what I've done wrong? Or maybe suggestions for a better solution (i.e.: one that works!) to my problem? Thanks!
The problem was a stupid logic error on my part: the line that read
if not(({Comment} in arrT1) and ({CName} like "T1*")) then
should have had the not moved inside the first parenthesis, so it negated ({Comment} in arrT1), and not the whole thing. That's what I get for blindly rushing in to modify existing code rather than sit down to think for a moment. Thanks to those who asked for clarification.

ZEND currency symbol is displaying 1

I'm using zend currency to display the currency based on locale. When I use the following code the symbol gets replaced by 1 instead of simply being removed:
$currency = new Zend_Currency($locale);
$currency->setFormat(array('symbol' => Zend_Currency::NO_SYMBOL));
What normally gets returned is this: € 2.500,01
but after the "setFormat" call I'm getting this: 1 2.500,01
I don't want the "1 " in there.
Any ideas on how to fix this?
Thanks.
Here's the ZF tutorial page for this. It looks like it will set a person in the right direction: zend currency tutorial page
You're setting the wrong option in setFormat. You need to set display to Zend_Currency::NO_SYMBOL. Like this:
$c = new Zend_Currency();
$c->setFormat(array('display' => Zend_Currency::NO_SYMBOL));
echo $c->toCurrency(2500.01);
Which outputs
2,500.01
The way you are currently doing it is literally setting the symbol to 1 because that's what the constant NO_SYMBOL evaluates to.

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".