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

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'

Related

How to reach the end of a chain of cells

I have a file with two sheets:
sheet_A
A B
1 Mr. Joe USD
sheet_B
A B
1 =sheet_A.A1 ???
sheet_B.B1 shall show the value USD. I know i could get it easily with =sheet_A.B1 but I do not want that.
If I enter into sheet_B.B1 =ADDRESS(ROW();COLUMN()-1) I get the output $C$1 and with =INDIRECT(ADDRESS(ROW();COLUMN()-1)) Mr. Joe.
How can I "navigate" through a chain sheet_B.B1 - sheet_B.A1 - sheet_A.A1 - sheet_A.B1?
Edit 1
Maybe I need something like this
=OFFSET(FORMULA(ADDRESS(ROW();COLUMN()-1);0;1)#
sheet_B.B2 shall show the content of sheet_A.B2 in relation of the value in sheet_B.A1
Here are two possibilities. Either formula produces USD in sheet_B.B1.
=INDIRECT(ADDRESS(ROW();COLUMN();;;"sheet_A"))
=VLOOKUP(A1;$sheet_A.A1:B1;2)
Documentation: ADDRESS, VLOOKUP.
EDIT:
One more idea: The following produces the string "=sheet_A.A1", which could be parsed for the sheet name and cell address. Perhaps you would like to use it to refer to sheet_A.B1.
=FORMULA(INDIRECT(ADDRESS(ROW();COLUMN()-1)))
However, as I commented, there is probably an easier way for what you are trying to accomplish.
Documentation: FORMULA.
EDIT 2:
Here is the formula you requested. It uses REPLACE to remove = at the beginning of the string.
=OFFSET(INDIRECT(REPLACE(FORMULA(INDIRECT(ADDRESS(ROW();COLUMN()-1)));1;1;""));0;1)

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!

Getting the first character in crystal report

I am creating a crystal report where the receipt number is written as V0000001 or N0000001. I want to get the first character because that is what differentiates these receipt numbers. There is label that says VAT Or No for receipt number V0000001, and a label that says NON VAT Or No. for N0000001.
Basically like this.
case V: VAT Or No:. V0000001
case N: NON-VAT Or No:. N0000001
I think that switch statement would be best, but I don't know how to write it.
The main question is, how would I change the label depending on the first character of the receipt number?
Thanks.
Write something like this:
If Left ("V0000001", 1)='V'
then "VAT OR NO"
Else If Left ("N000001", 1)='N'
Then "NON-VAT OR No"

Else part never getting executed in crystal report formula field

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.

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