CRYSTAL XI Field Editor - crystal-reports

What formula do I use to change the field format for Age so that it looks like (String) data?

Here are some choices:
Put your field on the report. Format your field and under Display String, use cstr(currentfieldvalue). (FYI: the currentfieldvalue is actually a function).
Make a new formula. Use cstr({tablename}.{fieldname}).

Related

Custom Function addition in crystal Report

I have to format a date string to a custom format like i need to convert "11/04/2016" to "11/D/2016". simply I have to replace the month number that is here 04 to an alphabet with the same sequence like 01 will be replaced by A and 02 by B and so on. I don't have any problem for writing logic for general purpose programming language. But I dont know how to add this custom functionality in crystal report.
I have checked formula fields but it seems they have predefined formulas whereas I need custom formula.
Is there any way to add custom function in crystal report and pass it some parameter and then it returns you come data that you show on the report ???
Thanks in advance !
Go to Report --> formula workshop and there go to New and there select custom function
Syntax would be:
Create a function Convert
Function(StringVar value) //this will take the input string
//Here write your logic and return a value.and close the function
Now you have created a custom function.
To use this create a new formula in functions go to custom functions and double click already create function
Convert("11/04/2016"); //close the window and place formula on design and refresh you get required output

IReport BigDecimal format "R$ #,##0.00" Monetary Value in Charts

I have a JasperReports chart, In the report, the field $F{soma} is BigDecimal, at thedatabase MySQL is Decimal(19,2). I'm using this sql: select SUM(valor) as soma to get the field $F{soma}.
Printing just $F{soma} i get labels like : 1.500,20. Without format expression. What i need is to show labels like : "R$ 1,520.20".
Tried this:
new java.text.DecimalFormat("R$ #,##0.00").format(Double.valueOf($F{soma}))
But no success, so if someone can point me a direction, i'll be thankful.
Have not reputation to post images, but links bellow are about the field types..
Field in MySQL:
Labels being printed (without format expression)
If your $F{soma} is a BigDecimal field then just write
new java.text.DecimalFormat("R$ #,##0.00").format($F{soma});
Use an instance of NumberFormat that has the right Currency to format the value. If the default Locale is giving you a problem,
Use NumberFormat.getCurrencyInstance(Locale inLocale) with the Locale you want, e.g.:
NumberFormat.getCurrencyInstance(Locale.US);
Use NumberFormat.getInstance() and setCurrency() to set the Currency you want, e.g.:
NumberFormat f = NumberFormat.getCurrencyInstance();
f.setCurrency(Currency.getInstance(…));

Formatting a string in jaspersoft?

In my report I have a string field with some numeric value, for example 123102,6. I would like to display 123 102,60 in my report.
Formatting numbers is a bugger in Java in general but gets even trickier with Jasper.
If your report works with a Locale that provides the space as the number group separator (like, for example, Locale.FRANCE does), then all you need to do is specify #,##0.00 as the value of the Pattern property of your field.
If that is not the case, or you are using several Locales, or you are resolving them at runtime, then the simplest way to solve your problem is to provide this:
new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(Locale.FRANCE))
.format(Double.valueOf($F{your_field_name}))
as the value of the Text Field Expression property of your field.

Return different datatypes crystal formula

I have a requirement where depending on the parameter selected the table field should be displayed as text or date. For eg, if the user selects a true, the OriginDate field which is a datetime type should be displayed as a date in the report else should be displayed as a text. I tried creating a formula an doing something like below, and then placing the formula in the details section of the report but it doesnt work due to different datatypes returned.
if {?Mailmerge}=true then
ToText({Travel.OriginDatetime}, "M/d/yy")
else
{Travel.OriginDatetime}
Is there a way I can accompalish the above requirement so that I do not end up creating 2 reports one with field displayed as text and other as date?
Try creating a formula that returns your field as a string totext({Travel.OriginDateTime},"M/d/yy") and overlay it with the original field {Travel.OriginDateTime} and conditionally suppress them based on the value of {?MailMerge} such that only one shows in any one instance of the report.
If I'm following you, you want to only show M/d/yy when ?MailMerge is true, otherwise yuo want to show the full date?
You can't show different datatypes in the same formula, so just convert them both parts of the conditional statement into strings:
if {?Mailmerge}=true then
ToText({Travel.OriginDatetime}, "M/d/yy") // 8/30/12
else
ToText({Travel.OriginDatetime}, "M/d/yy hh:mm:ss") // 8/30/12 02:06:00
I don't know what exactly your dates look like in the database, but you can use the above as a guideline into formatting your date based on the ?MailMerge parameter.

Crystal Reports query help if-then-else

Basically I have a field in my table called sex, and it's a boolean. true for male, false for female. How can I display it this way instead of as 0, 1?
You want to create a formula field and add the formula field to the report instead of the sex field. Something like this should work (my syntax may be slightly off)
if {MyTable.sex} = 1
then
"male"
else
"female"
If you are unfamiliar with formula fields they are just expressions you can use and display in the report. In the 'Field Explorer' side bar in Crystal Reports you can see list of all the Database Fields etc. Just right click on the Formula Fields and add a new one. After you create the formula field you drag it onto your report layout just like any other normal field.
Use a formula field. Put, say, #Sex into your report, then edit it to be something like:
//may need tweaked....
If {database.table.sex} then
male
else
female;
My Crystal formula syntax is really rusty, so that may not be right as written. It might need to be :
//may need tweaked....
Stringvar displaySex;
If {database.table.sex} then
displaySex = "male"
else
displaySex = "female";
displaySex
And the line-end (";") format might not be right....
If you right-click on the original database field and choose "Format Field...", you can set the Display String on the Common tab using one of the formulas above, instead of creating a separate formula to do the calculation.