jitendragarg
jitendragarg

Reputation: 957

Crystal Report formula not returning values sometime

I have a simple formula that I updated to use an IF condition. There is no error according to the CR designer. But, the formula still returns empty string.

This is the new formula

     IIF (IsNull({TBL_Delivery_Order_Header.DOHD_TotalDOPrice}), sum
({VIEW_Delivery_Note.Price},{VIEW_Delivery_Note.PODD_Delivery_Order_No}) , 
{TBL_Delivery_Order_Header.DOHD_TotalDOPrice})

This is the old formula.

sum({VIEW_Delivery_Note.Price},{VIEW_Delivery_Note.PODD_Delivery_Order_No}) 

If I leave only that sum part, value comes properly. If I put the same sum part in the IIF condition, it displays empty string instead. It is the exact same value and the condition is evaluated properly.

Edit: Values when record exists Values when record exists

Values when record does not exist Values when record does not exist

In first case, it works fine and displays 344222. In second case, it is supposed to take the other value from Price column, 18260. Instead, it shows empty.

Upvotes: 0

Views: 1465

Answers (1)

jitendragarg
jitendragarg

Reputation: 957

Never mind. I found the problem. It is probably the most retarded thing I have seen.

Anyway, problem was not the formula. Apparently Crystal reports decided that null in the IIF expression 2 is not valid, even though that's the whole reason for this IIF. So, it was throwing an exception because TBL_Delivery_Order_Header.DOHD_TotalDOPrice was null and was a part of the expression 2. Although it is not even considered during evaluation when it is null, Crystal report still didn't like it. As I said, retarded.

Anyway, there was a dropdown in the formula editor to decide what to do for null values. So, I selected "default values for nulls" instead of "exception for nulls". And now, all of a sudden everything is fine (even though I never declared any default value).

So, turns out formula was correct afterall. I just needed to ask crystal report to not throw a hissy fit when a null value is found.

Upvotes: 2

Related Questions