Crystal Reports formula: IsNull + Iif - crystal-reports

There are hints of the answer to this question here and there on this site, but I'm asking a slightly different question.
Where does Crystal Reports document that this syntax does not work?
Trim({PatientProfile.First}) + " "
+ Trim(Iif(
IsNull({PatientProfile.Middle})
, Trim({PatientProfile.Middle}) + " "
, " "
)
)
+ Trim({PatientProfile.Last})
I know the solution is
If IsNull({PatientProfile.Middle}) Then
Trim({PatientProfile.First})
+ " " + Trim({PatientProfile.Last})
Else
Trim({PatientProfile.First})
+ " " + Trim({PatientProfile.Middle})
+ " " + Trim({PatientProfile.Last})
but how are we supposed to figure out we can't use the first version?
The documentation for IsNull says
Evaluates the field specified in the current record and returns TRUE if the field contains a null value
and Iif gives
[Returns] truePart if expression is True and falsePart if expression is False. The type of the returned value is the same as the type of truePart and falsePart.
I suppose if you stare at that line about "type of the return value" you can get it, but...

Where does Crystal Reports document that this syntax does not work?
I doubt there is anyplace large enough in the entire universe to document everything that does not work in Crystal Reports...

I know I'm years late on this one, but I came upon this question while trying to figure out the same thing. Funny enough, I couldn't even find the answer in Crystal Reports documentation, but instead in a link to IBM.
Baiscally, if you're using Crystal Reports 8.x or 10.x, ISNULL and IIF don't work together. From the site:
Cause
There is a defect in Crystal Reports 8.x and 10.x that prevents the above formula from working correctly. The 'IIF' and 'IsNull' commands cannot function together, and that includes attempting to use "Not" to modify the IsNull command; for example, IIF(Not IsNull ()).
Resolving the problem
The workaround is to use an "If-Then-Else" statement. For example,
If IsNull({~CRPT_TMP0001_ttx.install_date}) Then "TBD" Else "In Progress"
So if you're using CR 8.x or 10.x (which we are), you're out of luck. It makes it REAL fun when you are concatenating multiple fields together and one of them might be NULL.

I think CR evaluates both IIFs true and false parts. Because you have "Trim({PatientProfile.Middle})" part there, which will be evaluated aganst null value, CR formula evaluator seems just fail.

try this:
currencyvar tt;
currencyvar dect;
tt :={ship.comm_amount};
dect := tt - Truncate(tt);
tt := truncate(tt);
dect := dect * 100;
if dect = 0 then
UPPERCASE('$ ' + ToWords (tt,0 )) + ' ONLY'
else
UPPERCASE('$ ' + ToWords (tt,0) + ' And ' + ToWords(dect,0)) + ' ONLY ';

Related

How do I use the "like" operator in Crystal Reports 2008 using a parameter

I am trying to create a formula based on a parameter that will allow the user to select a description of a supply item, or if none is selected to pull all values. Also want to be able to give them a parameter that allows them to type any part of the description using the "like" option. I can get the first part of the formula to work but not the second part. It is correctly pulling a typed in item or if none is typed it returns all values. Anything past the first "or" does not work. Should I create a separate parameter for the second part or can I use the same one?
IF HASVALUE ({?DESCR}) THEN{Command.DESCRIPTION} = {?DESCR} else true
or
( UPPER({Command.DESCRIPTION}) LIKE "*" + UPPERCASE({?DESCR}) + "*")
OR
( UPPER({Command.DESCRIPTION}) LIKE "*" + UPPERCASE({?DESCR}) + "*")
To the extent I understand your requirement you don't need anything after the if because though you give single character or a string your HASVALUE ({?DESCR}) returns true... hence you can modify your formula as
IF HASVALUE ({?DESCR})
THEN{Command.DESCRIPTION} LIKE "*" + {?DESCR} + "*"
else true
you can use UPPERCASE if you need.
Edit:
IF HASVALUE ({?DESCR})
THEN {Command.DESCRIPTION} LIKE "*" + {?DESCR} + "*"
ELSE IF HASVALUE({?NIIN})
THEN {Command.NIIN} = {?NIIN}
ELSE IF HASVALUE({?CLASS})
THEN {Command.CLASS} = {?CLASS}
else TRUE

Crystal Reports - Help displaying multiple Report Fields with one Formula

I am not a programmer by any means. I am but a curious lowly administrator attempting to modify a report for my needs. I have a Crystal Reports .rpt file that shows Purchase Orders and payments against those purchase orders. My problem is that the payment lines don't reference the purchase order number. Currently, I have to export the report then go through in excel and manually match each AP line to its matching Purchase Order number. I would like the AP line to also show the Purchase Order number.
There is a field in the report called "#Voucher_PO_ID" with the following formula in it:
if {LAGL019Q.RECORD_TYPE} = "3" then
if {LAGL019Q.SOURCE} = "AP" then
{LAGL019Q.TRANS_REF_NUM}
else if {LAGL019Q.SOURCE} = "PO" or {LAGL019Q.SOURCE} = "RQ" then
{LAGL019Q.PO_ID}
else " "
else " "
As I understand it, this formula is saying if the SOURCE is an AP (accounts payable) then for that line show the TRANS_REF_NUM (the check number for the payment), but if the SOURCE is a PO (purchase order) then show PO_ID (the purchase order number).
Again, knowing very little about programming, I was hoping it would be something as simple as modifying the if then statement to:
if {LAGL019Q.SOURCE} = "AP" then
{LAGL019Q.TRANS_REF_NUM} and {LAGL019Q.PO_ID}
But this does not work. I can append some text to the end of {LAGL019Q.TRANS_REF_NUM} by adding {LAGL019Q.TRANS_REF_NUM} + "blah" so I'm not sure why it won't add another field.
It just won't let me change this part of the formula:
" if {LAGL019Q.SOURCE} = "AP" then
{LAGL019Q.TRANS_REF_NUM}"
If I simply try:
if {LAGL019Q.SOURCE} = "AP" then
{LAGL019Q.PO_ID}
It still won't work and I'm not sure why? IF its an accounts payable line, I want it to show the corresponding PO_ID. It just shows a blank field when I do this even though I know the AP line has a corresponding PO.
I'm guessing there is some larger thing I am unaware of regarding how the actual database is setup. Maybe AP lines don't actually reference the PO_ID and I'm just assuming they do.
Most google searches I did brought be back here so I thought I'd post my problem. I've searched similar questions and they are mostly out of my league. Thanks ahead for any suggestions.
I think your only problem is that you're trying to use a logical operator (the AND keyword) instead of a string operator (The + or & characters). Hopefully it's as simple as this:
if {LAGL019Q.RECORD_TYPE} = "3" then
if {LAGL019Q.SOURCE} = "AP" then
"This is the transaction#: " + {LAGL019Q.TRANS_REF_NUM} +
", and this is the PO ID: " + {LAGL019Q.PO_ID}
else if {LAGL019Q.SOURCE} = "PO" or {LAGL019Q.SOURCE} = "RQ" then
{LAGL019Q.PO_ID}
else " "
else " "
If the {LAGL019Q.PO_ID}="AP" then this should result in:
This is the transaction#: <TheActualNumber>, and this is the PO ID: <TheActualPOID>
EDIT1: One other thought: How sure are you that the database actually holds valid PO#s for these records? If you tried to use if {LAGL019Q.SOURCE} = "AP" then {LAGL019Q.PO_ID} and it turned up blank, then that's a pretty good indicator that {LAGL019Q.PO_ID} is actually null for that record.

Formula won't display when certain fields are null

Similar to my first question. I want to show my address in a text box containing the fields as follows
{Company}
{AddLine1}
{AddLine2}
{ZIP}{State}{City}
{Country}
The line that concerns me (and hopefully some of you guys) is {ZIP} {City} {State}. What I want to produce is a consistent addressing format, so that there will be no blank space or indentation even if a ZIP, City or State field has been left blank in the DB. This line should still line up with the rest of the rows and not be indented. I also wish to insert commas between zip, state, city where they are relevant and leave them out where not. For this I have written a formula. Below:
If isnull({BILL_TO.ZIP}) or trim({BILL_TO.ZIP})= "" Then "" else {BILL_TO.ZIP}
+
(If isnull({BILL_TO.State}) or trim({BILL_TO.State})= "" Then ""
else(If not isnull({BILL_TO.ZIP}) and length(trim({BILL_TO.ZIP})) <> 0 Then ", " else "") + {BILL_TO.State})
+
(If isnull({BILL_TO.CITY}) or length(trim({BILL_TO.CITY})) = 0 Then ""
else(
If (not isnull({BILL_TO.State}) and length(trim({BILL_TO.State})) <> 0)
or
(not isnull({BILL_TO.Zip}) and length(trim({BILL_TO.Zip})) <> 0)
Then ", " else "")+ {BILL_TO.CITY}))
The problem is that when there is only a city (no state or zip entered) the formula itself will not display. It does however display when the others are present.
Can anyone see a bug in this code??? Its killing me
Thanks for the help.
Look forward to hearing from you guys!
There are a whole lot of if-then-elses going on in that formula so it's hard to tell, but if it's not displaying anything that probably means that you're using a field somewhere without handling its null condition first. Something simpler might be your best bet:
local stringvar output;
if not(isnull({Customer.Postal Code})) then output:=trim({Customer.Postal Code}) + ', ';
if not(isnull({Customer.Region})) then output:=output + trim({Customer.Region}) + ', ';
if not(isnull({Customer.City})) then output:=output + trim({Customer.City}) + ', ';
left(output,length(output)-2)
Create a formula field for each database field. For example:
// {#CITY}
If Isnull({BILL_TO.CITY}) Then
""
Else
Trim({BILL_TO.CITY})
// {#STATE}
If Isnull({BILL_TO.STATE}) Then
Space(2)
Else
Trim({BILL_TO.STATE})
// {#ZIP}
If Isnull({BILL_TO.ZIP}) Then
Space(5) //adjust to meet your needs
Else
Trim({BILL_TO.ZIP})
Embed each formula field in a text object.
Format text object and its fields to meet your need.
** edit **
I you have data-quality issues, address them in the STATE and ZIP formulas (because they will be a constant length). I would add the commas and spacing the text object.

crystal reports error in formula

so, i'm trying to generate a IF Then in crystal reports, basic syntax (i will use crystal syntax if that's what you give me). i have a value coming back from a stored procedure ranging from 0 to 4. depending on that number, i want to return back different phrases.
right now what i got:
formula = ""
IF {sp_cr_getSubsequentVisitBySubVisitID;1.Judgement} = 1 THEN
formula = "poor"
end if
if i change the ' 1 ' to ' true ', it'll save it, but it comes up with an error if i use ' 1 ' or ' "1" '. I've also tried using == and 1 = {sp_cr....}
Thanks for the help!
Crystal syntax, and Basic syntax AFAICT, require that you declare the variable to which you would like to assign a value. This is a tested example (my test field returns int as well):
stringVar formula := "";
if {sp_cr_getSubsequentVisitBySubVisitID;1.Judgement} = 1 then
formula := "completed"
else
formula := "n/a"
PS: don't forget the semicolon after the variable declaration.

Can't insert newline in msword form field using Powebuilder OLE

I have an application written in Powerbuilder 11.5 that automatically fills in form fields of a Word document (MS Word 2003).
The Word document is protected so only the form fields can be altered.
In the code below you can see I use char(10) + char(13) to insert a newline, however in the saved document all I see is 2 little squares where the characters should be.
I've also tried using "~r~n", this also just prints 2 squares.
When I fill in the form manually I can insert newlines as much as I want.
Is there anything else I can try? Or does anybody know of a different way to fill in word forms using Powerbuilder?
//1 Shipper
ls_value = ids_form_info.object.shipper_name[1]
if not isnull(ids_form_info.object.shipper_address2[1]) then
ls_value += char(10) + char(13) + ids_form_info.object.shipper_address2[1]
end if
if not isnull(ids_form_info.object.shipper_address4[1]) then
ls_value += char(10) + char(13) + ids_form_info.object.shipper_address4[1]
end if
if not isnull(ids_form_info.object.shipper_country[1]) then
ls_value += char(10) + char(13) + ids_form_info.object.shipper_country[1]
end if
if lnv_word.f_inserttextatbookmark( 'shipper', ls_value ) = -1 then return -1
The f_inserttextatbookmark is as follows:
public function integer f_inserttextatbookmark (string as_bookmark, string as_text, string as_fontname, integer ai_fontsize);
if isnull(as_text) then return 0
iole_word = create OLEOBJECT
iole_word.connectToNewobject( "word.application" )
iole_word.Documents.open( <string to word doc> )
iole_word.ActiveDocument.FormFields.Item(as_bookmark).Result = as_text
return 1
end function
Part of your problem is that carriage return is char(13), and line feed is char(10), so to make a CRLF in Windows and DOS you usually need to make char(13) + char(10). If these are out of order, many programs will balk. However, "~r~n" should have produced that for you.
I have success with (and I'm converting for brevity so it might only be close to correct):
lole_Word.ConnectToNewObject ("Word.Application")
...
lole_Word.Selection.TypeText (ls_StringForWord)
Maybe you can try other Word OLE commands to see if it's something to do with the specific command. (After the definition of the line break, I'm grasping at straws.)
Good luck,
Terry
Sounds like it may be a Unicode/Ansi character conversion thing.
for what its worth you could try this ...
http://www.rgagnon.com/pbdetails/pb-0263.html
Hope it helps.
I'm not using form fields, but I am able to insert newlines into a Word document from PowerBuilder using TypeText and "~n". Maybe you just need "~n".