DisplayString in Crystal Report - crystal-reports

What if we want to use DisplayString Method in Crystal Report but we want to apply this only on the basis of some parameter value ! ?
Like we will pass in parameter whether the use can see the purchase rate or not !
If not then we will print Asterisk instead of actual rate else do nothing !

Assumes a boolean parameter named {?hide}:
If {?hide} Then
Replace(Space(Len(ToText(CurrentFieldValue,"#"))), " ", "*")
Else
ToText(CurrentFieldValue)

Related

Crystal Reports - Only filter by parameter if it has a value, else return all values

How do you return all values if the parameter field is left blank? This is currently what I have in the selection expert:
if not(hasvalue({?parameter})) then true else {Table.Column} = {?parameter}
Set the 'Optional Prompt' property of the parameter to True:
Try this formula instead:
(not HasValue({?parameter}) OR {Table.Column} = {?parameter})
Using optional parameters in Select Expert formulas can be tricky. As soon as code is parsed that tries to say the parameter is equal to anything, it throws an error because the parameter has no value. The If...Then...Else logic still parses the entire block of code, regardless of whether the condition is true or false. In the formula above, if the parameter has no value in the first statement, the result is True, then the OR is parsed and the rest of the statement is ignored without parsing because it's result won't change the outcome of the formula.

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

Default Value for report

I'm trying too see how JasperReports Server gets the default value set in a report. I know how to set a default value in iReport, but I'm trying to come with a way to check for that value programmatically in Java.
In particular, I'm interested in a List of Values Single Value Radio Select, I am using a Resource Descriptor to get other Report data, but this seems to elude me. Any help at all would be greatly appreciated.
To set default value in case of null, you can do this
((!$F{field_name} == null) ? '0' : $F{field_name})
To get parameter type you can do
JRParameter[] params = jasperReport.getParameters();
for(JRParameter param : params) {
param.getName();
param.getDescription();
param.getDefaultValueExpression();
param.getNestedType(); // get parameter type that can be list, string
}
For detailed reference regarding Resource Descriptor you can check, they have given complete example http://jasperserver.sourceforge.net/docs/3-5-0/JasperServer-Web-Services-Guide.pdf

Condition expression - how to get REPORT TYPE in condition Expression

I would like to write expression like this:
{REPORT_TYPE} == "csv" ? "'" + $F{NUMBER_VALUE} : $F{NUMBER_VALUE}
where {REPORT_TYPE} should be xls, csv etc.
Have you any idea how to get report type?
You need to send a parameter from your server which will get these type of format like csv,xls. If this parameter has some value then you can use this expression. e.g. you have a parameter named reportType then you can make a syntax like this.
$P{reportType} ? "'" + $F{NUMBER_VALUE} : $F{NUMBER_VALUE}
if you want report type like csv then you need to give a value to this parameter, otherwise send it as blank string.
If you still get problem let me know.