Else part never getting executed in crystal report formula field - crystal-reports

I have a simple formula in crystal syntax which looks something like this :
if isdate(totext({Absence Details.Return to Work Interview Date})) = true
and {Absence Details.Return to Work Interview required} = true then
1
else
0;
This is the actual code of the formula
but the else part is never getting executed, when the condition is not true report just shows blank. I am not sure what I am doing wrong here.
Thanks in Advance.
- Amit

Maybe you have some null value in your fields - in such case crystal just returns null. You then need either "convert null values to default" setting for report or explicit testing against nulls.

Edit: NM, code was posted to the comments. Doesn't look like this is the issue.
My guess, assuming you've debugged correctly is that you've got a semicolon somewhere you shouldn't.
if {something} = x then
do something;
else
do something different;
instead of
if {something} = x then
do something
else
do something different;
This would cause the behaviour, assuming it doesn't choke on the orphaned else clause. But as the comments say, short of posting real code, we can only guess at what's going on. It could be as simple as your evaluation is always true.

Change the 0 to a 7 and see if it actually prints 7. Some report generation tools (and I have little experience with Crystal but quite a bit with others) will leave fields blank if they're zero - this often helps in reading the report by reducing unnecessary clutter.
If the 7's print out, then that's what the problem is, and it's a matter of figuring out how to get Crystal to output an actual 0.
That may be a matter of configuring the output field or even stting it to a textual "0" instead of numeric 0.
Of course, if that doesn't print out 7's, then feel free to let me know.

Related

Crystal Report XI If statement not working: not getting to else

I have a problem with an If statement in Crystal Reports XI.
This is my code:
IF {ANAGRAFICACF.CODLINGUA} = {DESCRARTICOLI.LINGUA}
THEN
{DESCRARTICOLI.DESCRIZIONEAGG}
ELSE
{RIGHEDOCUMENTI.DESCRIZIONEART};
The problem is that Crystal Reports retrieves only lines with the condition verified and completely ignores the else condition. So if in my documents there are 10 lines, it show me the only 2 that have the condition verified.
Can you explain why? I think this is OK. It's only a simple if statement.
There more details as you request:
I tryed also this code
IF NOT ISNULL({DESCRARTICOLI.DESCRIZIONEAGG}) AND {TESTEDOCUMENTI.CODLINGUA} <>0
THEN
{DESCRARTICOLI.DESCRIZIONEAGG}
ELSE
{RIGHEDOCUMENTI.DESCRIZIONEART}
For this last code I have this structure:
TESTEDOCUMENTI.CODLINGUA is numeric like in all other tables. So for English I've "1" for default I've "0"
DESCRARTICOLI.DESCRIZIONEAGG is the translation, so in DESCRARTICOLI
I've for example CODART CODLINGUA DESCRARTICOLI (Article code, Language Code, Article Translated Description)
RIGHEDOCUMENTI.DESCRIZIONEART is the standard italian description that I see in my ERP. So I've different columns including IDRIGA CODART DESCRIZIONEART (Line ID, Article Code, Italian Language Description)
Then I've TESTEDOCUMENTI table that contain the language CODLINGUA between columns. This table has the general setting of a single document.
So in my Cristal Report table setup I've linked the 3 tables RIGHEDOCUMENTI TESTEDOCUMENTI and DESCRARTICOLI and in particular TESTEDOCUMENTI.CODLINGUA with DESCRARTICOLI.CODLINGUA and RIGHEDOCUMENTI.CODART with DESCRARTICOLI.CODART.
When the translation is not stored in the article in the erp the DESCRARTICOLI.DESCRIZIONEAGG for this Article code doesn't exist. For example. If my CODART is "abg" in RIGHEDOCUMENTI I've CODART "abg" DESCRIZIONEART "ciao". Then in DESCRARTICOLI I've CODART "abg" CODLINGUA "1" DESCRIZIONEAGG "hI". If the translation is not stored the line in DESCRARTICOLI doesn't exist.
So my need is to verify if TESTEDOCUMENTI.CODLINGUA is different from "0" default language, but this is not enough because, most of my article hasn't the translation stored. So I need to show, the italian one, or a simple message telling me "no translation stored". I've tryed also to put this message instead of RIGHEDOCUMENTI.DESCRIZIONEART but it doesn't appear.
Another strange thing is that, in my document, on the same line I've also, in separate field in the report, the CODEART, MEASURES, PRICE. If I put directly RIGHEDOCUMENTI.DESCRIZIONEART without if statement, I see all those fields. Insted in I put the if statement I don't see neither thouse other fields..
It seems like that the first think it go to read the Translation Table DESCRARTICOLI, it doesn't come back to read the original one, so end the cicle through lines, without reading all parameters stored in the RIGHEDOCUMENTI tables, containing all data that don't appear in the report.
I hope to have been more clear now.
Thank you!

Crystal Reports XI - Only show Details lines ending in 'C'

Hopefully a straight forwards question.
I have a Report that runs from a stock system, it prints to show all the products in a customers order, as well as a general 'Thank you for your order..' message.
In the details section it currently shows Product and Product Description for everything within that order.
I have a new client though who wants another version of this report, one which only shows the details lines where the Product Code ends in the letter 'C'.
I'm guessing I need to suppress the details section but I'm not sure what Formula I should be using.
I also can't say for certain that all their product codes will remain the same length. I think about 95% of them will be 8 characters, but any 'special edition' versions may have extra characters in.
Thanks in advance for your help.
A suppression formula needs to return a Boolean value, so a formula checking the last character in your Product Code field should do it:
right(trim({ProductCode}),1) = 'C'
To make it work for a single client, you could do something like this (warning: I'm rusty with Crystal syntax - take it with a grain of salt):
IF {CustomerCode} = 123
THEN right(trim({ProductCode}),1) = 'C'
ELSE false
right(trim({ProductCode})) <> 'C'

I need the details section to suppress if a custom date field is blank in Crystal Reports

I have the following suppression formula in the details section:
{JCJM.udRough} <= #1/1/2013 12:00#
AND
{JCJM.udTrim} <= #1/1/2013 12:00#
and it works. However, I also need it to suppress if the udRough or udTrim field is blank. When I try to add
OR {JCJM.udRough}=""
it says that a date-time is expected where the blank quotes are.
Can someone please help?
As a general rule in CR, if a field can be null then you should explicitly check for that case first in a formula, otherwise it will not evaluate properly. Otherwise, CR will treat it like an unhandled exception.
So in your case, CR is short-circuit evaluating the expression {JCJM.udRough}<=#1/1/2013 12:00# as the very first thing, sees that the field is null, and stops evaluating the rest of the formula since it has encountered an exception.
What you need is:
(isnull({JCJM.udRough}) or {JCJM.udRough} <= #1/1/2013 12:00#)
and (isnull({JCJM.udTrim}) or {JCJM.udTrim} <= #1/1/2013 12:00#)
Try
if ISNULL({JCJM.udRough})
Then true
else false
This is from my understanding from your question if you are searching for something different let me know will try to answer it.

Database-field with false as value sent over XSD to Crystal Reports is evaluated as true

The application I work on is using a Crystal Reports to present reports to the user. I am using Visual 2010, but the report was created by a previous employee some years back using Visual2005.
The basic setup is that the client application make a request to the server that uses a xsd that define the data-set it sends back. Generally this work like expected, but I am having some problems with evaluating booleans.
A recent task consider of adding the dataset with a field name TrueWeekday that control if certain numbers should be printed out or not depending on if a date is a regular weekday or have some special local meaning that might affect the sampled data. The data is always used in some formulas so I can not exclude it from the dataset.
My first attempt involved defining the new field as a boolean and in the formula for the report I wrote
if {Header.TrueWeekday} then
CStr({Detail.Flow})
else
""
This had the result that no matter if the value in TrueWeekday was false or true the flow was presented. I debuged the server to verify that the variable indeed got the expected value so the problem happened in the Crystal Reports or in the transfer of data to Crystal Reports.
To solve this particular problem within the timeconstraints of the task I changed the field to the type string and wrote
if {Header.TrueWeekday} = "false" then
CStr({Detail.Flow})
else
""
This worked like a charm.
My problem here is not urgent since I have a working solution, but I am worried that this problem might create more subtle dataintrigity problems.
What might be the cause of this and how do I solve it?
Header.TrueWeekday is probably being passed as a string so that when you do if {Header.TrueWeekday} its testing a string as a boolean in which case if the string contains anything it evaluates to true and thus causes your problem
Work in a different project made me realize that .Net is probably serializing the boolean as the text string true/false. If then Crystal Reports does sloppy import and only check
input != 0
you will get the result that both true and false map to true after the transfer.

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