Show text if Section is suppressed - crystal-reports

I am trying to display a certain message in the Report Header section based off if the Report Footer section is suppressed.
I need something like... ifSuppressed()
Does something exist like that in Crystal Reports?
In case something similar does not exist... here is my ultimate goal.
I need a value to be determined in the Report Footer section. If said value is greater than another value then I need a message to be displayed in the header.
The problem which I believe is that one of the values used in the calculation in the footer is from a sub report which I had to put in the Page Header to get what I needed. Therefore, I could not pass the value above the Page Header to the Report Header so I am trying to see if I could determine if a section is suppressed (Which is based off some variables in the sub report) and go from there.
Sorry if that is confusing and can elaborate if needed.

Of course after I post a question... I typically figure it out.
So here it is.
I created another formula to grab the SUM I was looking for with the running total.
I also created a formula to grab the amount I need to compare to (Which was from the subreport).
I then created an additional header so I have now header 1 and header 2. I put the subreport in header 1 and the two formulas in header 2. This way I can grab the sum and pass the number from the footer to the header because the subreport is above in header 1.
I then could do my comparison and display my message correctly.

Related

Crystal Reports, driving Header/Footer decisions based on a specific detail row

I have a simple report that can display many detail rows.
I want to target a specific row and use it's values to populate aspects in the Report Header and Footer.
For example , I know what the minimum(primarykey) within the detail rows that I display.
A simply formula can capture that.
I want to pick up other attributes of the row with the minimum(primarykey) and display in the header or footer.
I therefore want to select a specific row select and use its data in the header and footer, something like:
Select NAME, DATE from DETAILSROWS where DETAIL.PRIMARYKEY = minimum(DETAIL.PRIMARYKEY)
I've thought about using a subreport here, and passing values back to the main report, but that doesn't see to the way to go... I've tried for example passing minimum(DETAIL.PRIMARYKEY) to the subreport so that the sub loads only the row I want, then passing the values back via shared variables. But I don't want to display the subreport, and if I suppress it, my shared variables don't seem to populate.
Displaying the values in the Report Footer would be easier than the Header. All you'd need to do is compare each row's primary key to the value of maximum({DETAIL.PRIMARY_KEY}) and save off the values. So something like:
stringvar saved_column1;
stringvar saved_column2;
if {DETAIL.PRIMARY_KEY}=maximum({DETAIL.PRIMARY_KEY}) then
(saved_column1 := {DETAIL.COLUMN1};
saved_column2 := {DETAIL.COLUMN2})
For the header, really the only way I can think of is to use the subreport like you're already doing. I'd just format the subreport to display itself, though, and not mess around with shared variables.
Okay so it turns out the SUBREPORT option is the way to go.
SUBREPORT is a bare minimum report that has passed to it, the lookup value you are after.
Long winded, I link to it using a formula that holds essentially: minimum(DETAIL.PRIMARYKEY).
In turn the subreport selects that single detail record.
Within the subreport, build a Formula and drop it the into its report header:
WhilePrintingRecords;
Shared DateTimeVar subCreationDate := {DETAIL.CREATIONDATE};
Shared StringVar subCreationName := {DETAIL.CREATIONNAME};
Finally, suppress all the the sections (delete what u don't need) on the SUBREPORT, and close.
On the main report... Not sure but it looks like the SUBREPORT can sit anywhere.
And because you've suppressed elements WITHIN the SUBREPORT, it won't display on the main report.
(So no need to suppress on the main report - and if you do suppress it there, it won't work anyway!)
Now create your formulas (in my case 2) on the main report and in each, repeat the variable declaration.
Shared DateTimeVar subCreationDate
Shared StringVar subCreationName
Again, each of the above sit in their individual formula declaration.
And from there, you now have "standard" formulas to work with on your main report.
They can be referenced just like any other!
Thx Ryan - your answer certainly helped me get where I need to go - u still get my +1!

Crystal Reports: How can a not on-demand subreport be displayed as a link in the main report

I am struggling to fix a subreport where data is obtained at the point when the main report is generated and the subreport to be displayed as a link, similar to an on demand subreport.
The issue that I have if I use a non on demand subreport is that it cannot be represented as a link, it is displayed inside the main report. As well as an on demand report is not suitable to my case because the data is retrieved when the subreport is opened.
I would appreciate any help.
Thanks in advance!
You have to take the another header for subreport and also drilldown the Header and on the Suppress formula write the formula Drilldowngrouplevel = 0 and for the Sub Report take the another detail section and on the supress formula write the formula Drilldowngrouplevel = 0.
This will definitely work, because I tried it.
Can you add a group level to the subreport and add a single line into the group header?
This will mean you will have to drill down twice to get the data though.

How can I get a field to print at the top of every page in JasperReports?

I am using iReport 3.7.6 to create this report.
I have a report based off of an XML file. There is a 2-column master report and it has a detail band with a subreport.
I have a field called "Name" in the subreport. I want it to print at the top of every page. Or even at the top of every column. I have tried virtually everything I know how to do.
"Print When Detail Overflows" doesn't work, because this setting is in the detail.
I sure hope I don't need to create a subreport for every report break I want. I'll have like 4 or 5 subreports.
Is there some way to determine when the page has changed, and then use that event in a "Print When" expression?
Here is one solution, presuming the value does not change between pages:
Write a query for a subreport that obtains only the Name value.
Change the dimensions of the subreport to be as small as necessary.
Place the subreport in the page header band of the master report.
To answer your question accurately, more details (such as pictures of what you have versus what you want) would be helpful.
you can use pageCount variable which is implicitly available in jasper reports to know whether the page has changed or not.

Crystal Reports: global variable running total not displaying in header

Using Crystal Reports I'm trying to display the running total of a database field in the header where all the labels are.
I've attempted to do this by placing the running total (RTversion) into a formula field with the following:
Shared stringvar CurrentVers;
CurrentVers := {#CurrentVers};
and then in the page header section I have the following:
Shared stringvar CurrentVers;
EvaluateAFter({#currentVers});
CurrentVers;
with {#CurrentVers} running the 1st largest number.
Is this incorrect?
Update: The goal is to display the latest version in the header near the labels to show what the current verseion is for comparison.
Running-Total Fields, in my experience, only work in the footer sections.
You will need to create a manual running total.
Add a formula field to the Details section that populates a Global variable with whatever you are trying to capture. Something like:
//use WhileReadingRecords if the values can be gathered as the report pulls in values from the database. Otherwise, use WhilePrintingRecords.
WhileReadingRecords;
Global Stringvar CurrentVers;
//logic here to capture what you want
CurrentVers:=...
Add another formula field to the Header section. Add these two lines to it:
WhilePrintingRecords;
Global Stringvar CurrentVers;
Create a formula like this
formula = Count ({Field to count},{GroupFieldName})
and place it in group header section.
I figured it out..
I had to add a subreport to the main report. I copied the main report and renamed it as a subreport. In the subreport, I added a shared variable and then passed it to the main report. The trick is to place the subreport in the same group header, but a separate section above the section that needs to be suppressed. I actually added the following sections:
New section (same group-I placed subreport here; do not suppress)
New Section (same group - I placed shared variable value here; do not suppress)
Original Section (same group that has a header I need suppressed based on a running total)
If {#CurrentVers} is a regular running total field, you should be able to place it in the page header directly rather than resort to an additional formula. I don't see the need for either formula field here, unless there's something unusual in the composition of {#CurrentVers} and a 'largest number' running total shouldn't require anything out of the ordinary.
You can solve this with just one formula field:
WhilePrintingRecords;
// Enter logic here e.g.
// maximum({mytable.myfield});
The WhilePrintingRecords; forces the formula to not be evaluated until all records have been read from the database, and therefore the formula field will display the correct result even if placed in a header.
The key I found is that the formula field being passed needs to be placed on the subreport. I placed mine in the footer then suppressed it.

Page header & footer on Summary band

I have read this thread:
http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=67923
I would rather not repeat the page header and footer for each crosstab, as there are six of them, and if the header needs to change, I'd like to change it only once.
The problems include:
Putting the crosstabs on their own page (should be easy enough with a page break).
Making the crosstabs include the same header and footer as the rest of the report.
Reusing the header & footer from a single source.
Making the crosstab be shown before the data (not all that important, but would be nice).
The report appears as follows:
It would be fantastic to have the crosstab appear on a page by itself, including the same header and footer as the rest of the report, rather than looking like the image above.
The report is set up as follows:
Any ideas?
The solution involved these changes:
Provide a dummy query for the main report (e.g., SELECT 1 FROM DUAL)
Create a new subreport for the data details, based on the former query for the main report
Add a second detail band (Detail 2)
Place the six subreports in the first detail band (Detail 1)
Place the data details subreport in the second detail band (Detail 2)
Pass the parameters from the main report into the data details subreport
Reduce the data details subreport's margins to zero
Delete the Summary band (no longer required)
This allows full control over the crosstab's report position while reusing the same header and footer for both the crosstab and the data details.