Checking if Something is Empty String Stopped Working

So I have been using a function in my workflow that checks to see if “aValue.Equals(”")" and it was working totally fine until now. All of a sudden it is throwing an error saying that the “Object reference not set to an instance of an object”

I have no idea why. If someone could help that would be great. Thanks.

Hi.

You can solve this a few ways.
First I would try doing aValue.ToString.Trim.Equals(""), but I think that might not work
Second, you can set “aValue” to “” by default, either in the Variables tab or with an Assign, so it starts off with an initial value of empty string.
Lastly, you can embed a condition in your condition like so:
If(aValue isNot Nothing, aValue.Trim.Equals(""), True)

The last solution is not really needed but does add some robustness.
Second solution is probably easiest to implement.

Regards.

1 Like

For checking string variable is empty or not. Better use static methods string.isnullorempty(avalue)

I am checking if the string is empty of nothing with your method String.IsNullOrEmpty(variable1.ToString.Trim)
But always get an error “Object reference not set to an instance of an object” if the string is Null.

I have tried an IF condition as:
variable1 is DBNull.value OR variable1.tostring.trim is ("")
But it does not work too.

If (variable1 Is DBNull.Value, variable1.toString.trim=(""), false) works great. But not if I need to check both True and False.

Can someone please help me with an issue.
Thanks
Anna

variable.ToString would throw error if variable =null. But Convert.ToString(variable) would be working in both cases.

Hi Uemoe,
thanks for the quick reply.

I am checking if the string is Null or “”.
If Null or empty -> assign a default value.
If not Null or empty -> check the sting.length.

“convert.ToString(variable) is DBNull.Value” does not work in the IF condition if value is not empty.

I don’t understand dbnull part. First from where our variable is coming? Second before call non-static methods on variable you should null-guard condition or use static methods. In your case check should be string.IsNullzOrEmpty(convert.ToString(variable))

This will work for not initialized objects:

IsNothing(variable)

For example:
image
As you can see, the variable is not initialized:


Output:
image