Hello,
I'm using WebServiceDataSource to connect with database through odata. In database there is InventoryDocDetail table which has Product property referenced to Product table.
I'm connecting to InventoryDocDetail and printing the product's Sku property on my report. The problem here is InventoryDocDetail.Product may be null. In this case, I just want to print nothing. Currently it gives null reference exception error(See attached Error.JPG file).
I saw many forums, but no one helped me. For example, I wrote like this expression in textbox: = iif(Fields.Product is null, "this is null", Fields.Product.Sku), but it still showing error when product is null.
1. How can we solve the issue?
2. Can we use C# expression here like this: "= Fields.Product?.Sku" ?
4 Answers, 1 is accepted
You may use operators where only one of the operands gets evaluated depending on the condition, hence if the other one is null this will not result in an exception. With functions all their arguments get evaluated, and then the function gets executed. Currently, our Expression engine does not support syntax like "Fields.Product?.Sku".
For example, with the "?:" operator (check Logical/Bitwise operators) the expression may look like :
= IIf(CStr(Fields.Product) = "", 0, 1) = 1 ? Fields.Product.Sku : "this is null"
You may test also with the "??" operator. For example, you may check whether a Field is null with an expression like :
= Fields.Product ?? "this is null"
Regards,
Todor
Progress Telerik
Hi,
I tried your example above, but still showing error related with JsonDataObject. See attached picture. 1st picture is about printing product's sku with 2 ways. 2nd picture is result of those example. So, what do you suggest in my case?
I have made a mistake. Note that IsNull requires two arguments. There are also known issues with the JsonDataSource - check JsonDataSource evaluates NULL values incorrectly and Check with "?" in the expression for null values items in our Feedback portal. Here is a workaround I will suggest :
= IIf(CStr(Fields.Product) = "", 0, 1) = 1 ? Fields.Product.Sku : "this is null"
I have attached a sample report to demonstrate the approach.
I have corrected the expression also in my previous reply so that our users do not get confused by it.
Regards,
Todor
Progress Telerik