Jump to content
We've recently updated our Privacy Statement, available here ×

How to use a count field variable in print when expression of any band in the report


7nirmalrana77

Recommended Posts

Hi Team,

I have been trying to create a variable which will count the number of records in a database field. I do not want to display the record count but want to use it in Print When expression.

To provide more details i have created a Group header and have only a text to display which is "No records found for this type". 

Have created a variable Count_Field (Integer) , reset type = "Report" Increment is none and in Expression : $F{FULL_NAME} which is the field i want to count.

My condition is when the count of the field (FULL_NAME) Count_Field == 0 then print the band otherwise do not print. 

Now i am putting the condition on the Group header band Print when $V{Count_Field}== null ||  $V{Count_Field}==0 , but it works some day and does not work another day.

 

Could you please assit how can i use this variable to check the count of records? If i want to put condition as Print when only count =20 then how can i print it?

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

The PrintWhenExpression is normally evaluated at current runtime... so in a group-Footer it could work... but if you place your TextElement in GroupHeader, you can set the evaluation-Time to group.... but the PrintWhenExpression is evaluated BEFORE ... so at runtime... when the header is printed. Removing Elements AFTERWARDS should not be possible, as this could cause reallocate other (following) elements... so a NO GO...

What I've done in former times.... not to use a PrintWhenExpression but use an IfThenElse -  TEXTEXPRESSION with EvaluationTime set to Group:

$V{Count_Field} == null || $V{Count_Field} == 0 ? "No records found" : $V{Count_Field} + "records found"

 

hth + regards

C-Box

Link to comment
Share on other sites

Thanks for your response! It helped..

But I have a query still because there are count functions used in suppress condition in a crystal report which we need to replicate in Print When expression. Do we have any other function like count on a column in Jasper?

Link to comment
Share on other sites

Of course you could count also at column level.... just take a look at the reset-time COLUMN, so the value will be resetted at each column break. 

But I still don't understand what you want to achieve. You said "suppress condition in crystal reports" ?!?! As in your initial post you want to "suppress" the whole group-header band if the actual group count is 0, right?

So in this case, the report engine should know in advance not to print the whole groupheader-band if there are no records found in the group at the end..... so as the variable is incremented at each detail record how should the engine do that? 

So I would try to use a SubSelect within the main query and ask for your group-count something like "SELECT COUNT(FieldName) FROM TABLEX WHERE ConditionField = X ..." Or perhaps you could use a grouped query for the main report and use a SubReport with an own sub query for represent the detail-records for each group? So this would fullfill your needs much easier as you already know at group-header level if there are some records or not!??!

hth + regards

C-Box

Link to comment
Share on other sites

If you just want to display a message when there's no data, have you tried using "No Data" band. Add the band and put the message in it and in the report properties, select "No Data Section" in "When No Data Type".

Not sure what you're doing with variables and group band. If you want to know the current row number of the data source, use $V{REPORT_COUNT}. However, if there's no data in the data source, When No Data Type setting will be used instead.

If you want to display a message on 20th record, why not just put a static message in the detail band and set the Print When Expression to $V{REPORT_COUNT} == 20 and set other elements in the detail band to have Print When Expression to $V{REPORT_COUNT} != 20

Link to comment
Share on other sites

The NO-DATA-SECTION wouldn't help, as the GROUP-HEADER should contain the text "no data for this element" just for the grouped part of data... so the NO-DATA-SECTION would just appear, if the whole main query returns no data.... that's why - in my humble opinion - refactoring the design and queries into one grouped main and detailed subreport would make the life much easier in this case.

C-Box

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...