【Null Exception】Check if Queue_Test_Data_item("key").tostring has a value

I have implemented the following logic, but I am still getting a null exception. How can I solve this? Thank you!!

image

If Condition:
String.IsNullOrEmpty(Queue_Test_Data_item(“LoanRate”).ToString) or String.IsNullOrWhiteSpace(Queue_Test_Data_item(“LoanRate”).ToString)

※Queue_Test_Data_item is a Dictionary type variable for storing items retrieved from the queue…

Hi

Pls try with this single expression itself

String.IsNullOrEmpty(Queue_Test_Data_item(“LoanRate”).ToString)

And make sure there is a field named LoanRate in that queue item

Cheers @111962

Hi,

Can you try the following expression?

Queue_Test_Data_item("LoanRate") is Nothing OrElse String.IsNullOrEmpty(Queue_Test_Data_item("LoanRate").ToString) OrElse String.IsNullOrWhiteSpace(Queue_Test_Data_item("LoanRate").ToString)

Or the following might be better.

(Not Queue_Test_Data_item.ContainsKey("LoanRate")) OrElse String.IsNullOrEmpty(Queue_Test_Data_item("LoanRate").ToString) OrElse String.IsNullOrWhiteSpace(Queue_Test_Data_item("LoanRate").ToString)

Regards,

1 Like

Thank you for your quick reply.
I tried this, but still had the same error.
and I’m sure there is a field named LoanRate in the queue item.
image

Thank you for your quick reply.

I tried the code below this one, and there was no error.

Queue_Test_Data_item("LoanRate") is Nothing OrElse String.IsNullOrEmpty(Queue_Test_Data_item("LoanRate").ToString) OrElse String.IsNullOrWhiteSpace(Queue_Test_Data_item("LoanRate").ToString)

But, When I tried this, I got the same null exception.

(Not Queue_Test_Data_item.ContainsKey("LoanRate")) OrElse String.IsNullOrEmpty(Queue_Test_Data_item("LoanRate").ToString) OrElse String.IsNullOrWhiteSpace(Queue_Test_Data_item("LoanRate").ToString)

I wasn’t quite sure what was causing the this, but I was able to resolve the error using the first method., thank you very much!!

1 Like

Hi,

Second code checks if key named “LoanRate” exists. As it seems the key exists In this case, the first one will be solution.

FYI: This expression uses OrElse operator. As it helps you in this case, see the following in detials.

Regards,

1 Like

I see. Thank you for the reference. :bowing_woman:

1 Like