Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crystal Reports Custom IsNull Function

I am trying to create a custom IsNull Function in Crystal Reports; the function must act the same way as the IsNull Function in MS SQL Server. I want to specify a field, and if the field is null, then it must be returned with a value I have specified.

IsNull({myField},0) or
IsNull({myField},'Hello World') 

I have encountered that I have to create a separate function for number fields and a separate function for text fields. I also found that Crystal does not allow the use of standard functions inside of a custom function, for instance the ISNULL Function:

Function(NumberVar param, Numbervar setter)
IF ISNULL(param) THEN setter ELSE param

and

Function(StringVar param, StringVar setter)
IF param = NULL THEN setter ELSE param

Does anyone know how I can create a function like this in Crystal and a work around for the ISNULL inside of a custom function?

like image 833
JPVoogt Avatar asked Aug 13 '12 13:08

JPVoogt


People also ask

IS NULL function in Crystal Report?

IIF and IsNull are functions in Crystal Reports that are used in formulas to test fields for blanks, empty strings, missing values and NULL, then return some valid output. This is especially helpful when preparing a report, since these values can cause blank lines to be printed.

IS NOT NULL condition in Crystal Report?

If value isn't null, your code should put it into the shared variable. If it is null, your code can safely ignore it and do nothing.


2 Answers

You can't pass a null value into a custom function, so it's pointless to use crystal's isnull function inside one. Only option is to write it like...

if isnull({myField}) then 0 else {myField}
like image 84
dotjoe Avatar answered Oct 04 '22 19:10

dotjoe


I found this issue, in the formula editor there is a drop down in the header that indicates:

  • Exception for Nulls
  • Default values for nulls

Select the second one ( Default values for nulls)

 

like image 20
user3558031 Avatar answered Oct 04 '22 19:10

user3558031