The keyword 'then' is missing - crystal-reports

{FUELDELAY.STATUS} = "VENDOR RESPONSIBLE" and {FUELDELAY.FLIGHTDATE} in {?begtime1} to {?endtime1}
and if {?fuelserviceprovider} != "" then {FUELDELAY.FUELSERVICEPROVIDER} in {?fuelserviceprovider}
and if {?station} != "" then {FUELDELAY.STATION} in {?station}
I don't see the syntax error, but Crystal Reports keeps telling me that "The keyword 'then' is missing."
Do any of y'all see the error?
Any help is much appreciated--thanks!

You can try the following:
IF {FUELDELAY.STATUS} = "VENDOR RESPONSIBLE"
AND {FUELDELAY.FLIGHTDATE} in {?begtime1} to {?endtime1}
AND {?fuelserviceprovider} != ""
AND {FUELDELAY.FUELSERVICEPROVIDER} in {?fuelserviceprovider}
AND {?station} != ""
AND {FUELDELAY.STATION} in {?station}
THEN
//some code if true
ELSE
//some code if false

There are at least two main errors in your syntax.
The !=-operator is not valid Crystal-Syntax -> use the not-operator or <>-operator instead
and if ... is not valid. The syntax is as follows (The else-part is optional):
if <condition> then
'Do something
else
'Do something different
So the following formula should work.
I'm not sure if this is exactly what you need, because it's not clear from the question.
if
{FUELDELAY.STATUS} = "VENDOR RESPONSIBLE" and
{FUELDELAY.FLIGHTDATE} in {?begtime1} to {?endtime1}
and {?fuelserviceprovider} <> "" then
{FUELDELAY.FUELSERVICEPROVIDER} in {?fuelserviceprovider}
else if {?station} <> "" then
{FUELDELAY.STATION} in {?station}

Related

The Keyword then is missing Crystal reports

I am getting an error The Keyword then is missing in my code, I cannot find why it is giving me the error. The error cursor is after the "Various" Any ideas
IF (isnull({148_vwWorksOrderReportFeed.Expr6})) OR IF (isnull ({WorksOrderHeader.udfCustomer})) OR IF (({WorksOrderHeader.udfCustomerVarious})) = False Then "Stock" Else IF not isnull({148_vwWorksOrderReportFeed.Expr6}) THEN {148_vwWorksOrderReportFeed.Expr6} Else IF not isNull({WorksOrderHeader.udfCustomer}) THEN {WorksOrderHeader.udfCustomer} Else If {WorksOrderHeader.udfCustomerVarious} = True THEN "Various"
I have tried various syntax and googled the life out of it but cannot find anything to explain why it is happening, could be my lack of knowledge in stsntax of course.
Try the following:
IF (isnull({148_vwWorksOrderReportFeed.Expr6})) OR (isnull ({WorksOrderHeader.udfCustomer})) OR ({WorksOrderHeader.udfCustomerVarious} = False) Then "Stock" Else IF not isnull({148_vwWorksOrderReportFeed.Expr6}) THEN {148_vwWorksOrderReportFeed.Expr6} Else IF not isNull({WorksOrderHeader.udfCustomer}) THEN {WorksOrderHeader.udfCustomer} Else If {WorksOrderHeader.udfCustomerVarious} = True THEN "Various"

Is therre any crystal coding style to prevent nil error in compiling

I am a newbie of crystal and amber framework, and when I try to rewrite a rails app with db to amber, I encountered a lot of compile error complained about nil matching, even sometime it is clearly not nil I think, such as
doc = Document.first("where id = ?",params[:id])
if doc.title.nil?
title = ""
else
title = doc.title
end
I must write as such
doc = Document.first("where id = ?",params[:id])
title = ""
if doc
if doc.title.nil?
title = ""
else
title = doc.title.not_nil!
end
end
I think maybe it is because of my code style.
So is there some good code style document for crystal or
good practices?
I'm new to crystal too however, you can remove the nested if block with a guard clause.
return unless doc
Also, you can set a default value with granite. So where you put title = "" can be removed if the default value is an empty string. With that in mind, you new code would be:
doc = Document.first("where id = ?",params[:id])
return unless doc
title = doc.title

Crystal Report-FORMULA

I am trying to create two FORMULA fields in Crystal Reports with the same Column in the Database using the following Syntax:
FORMULA1- COLL_DATE
if Collection_Rejection_Desc = 'Cleared'
then Coll_Rej_Dt
else null
FORMULA2- REJ_DATE
if Collection_Rejection_Desc = 'Rejected'
then Coll_Rej_Dt
else null
But it is giving me error saying "a Date and Time Field is expected here"
How can I resolve this?
you can't give one value as date time and other as null in a if condition.. change like this:
FORMULA1- COLL_DATE
if Collection_Rejection_Desc = 'Cleared'
then ToText(Coll_Rej_Dt)
else ""
FORMULA2- REJ_DATE
if Collection_Rejection_Desc = 'Rejected'
then ToText(Coll_Rej_Dt )
else ""
You may want to return Coll_Rej_Dt when the condition is correct, otherwise return null.
you can use Switch by replace if condition. Because in if condition, you need to return same data type in true part and false part.
So, try this...
Switch (Collection_Rejection_Desc = 'Cleared', Coll_Rej_Dt)
Switch (Collection_Rejection_Desc = 'Rejected', Coll_Rej_Dt)
this will return value when the condition is true.

Hide static text field when $P{} is ""

I'm using iReport 4.7.1. The report contains a static field "Date Validated:" and a text field "$P{DATE_VALIDATED}" which i can confirm is "" empty. I want to hide "Date Validated: " text when $P is empty.
I have tried the following so far:
I have added the following line in the property (print when expression) of the static field which has static text "Date Validated: " :
$P{DATE_VALIDATED} == "" ? new Boolean(false) : new Boolean(true)
I also tried the following variations:
$P{DATE_VALIDATED} == "" ? "" : "Date Validated:"
$P{DATE_VALIDATED} == "" ? Boolean.FALSE : Boolean.TRUE
But static field is still showing up. I also tried putting just Boolean.FALSE to hide it completely to test and see but text is still showing up.
You can try the below expression in print when condition
!$F{DATE_VALIDATED}.isEmpty() && $F{DATE_VALIDATED} != null && $F{DATE_VALIDATED} != ""
Hope this should solve your problem.
Thanks viki888 for the quick answer, that's an improvement to what i am trying to do, i'll up vote it, but the problem in my situation was i wasn't Compiling the Report after saving it, because i didn't know i had to and there isn't an obvious option/menu item or icon except tiny little hammer on the toolbar on designer window that says Compile Report... :)
So in my case compiling the report solved the problem for me. and
$P{DATE_VALIDATED} == "" ? Boolean.FALSE : Boolean.TRUE
is working fine.

Inline if condition with nil in swift

I am trying to use inline if condition as follows:
topDisplay.text = topDisplay.text!.rangeOfString(".") ? "Sth for true" : "Sth for false"
The idea here is if there is "." in the topDisplay.text! then do something, if not, do something else. The method, rangeOfString, returns nil if no "." is found. So I am wondering is it possible to check nil within inline condition expression.
((btw, you might find out that I am trying to add "." button for calculator assignment in Stanford's online course, and to use only one line to implement this function as the hint describes))
So I am wondering is it possible to check nil within inline condition expression.
Sure. rangeOfString(".") != nil is a boolean expression which can
be used as the condition in the conditional expression:
topDisplay.text = topDisplay.text!.rangeOfString(".") != nil ? "Sth for true" : "Sth for false"