How to check for null values of a string

1
I have a string which can be empty. I have added a decision activity in which I have to check if the string is empty. So, I have tried expression $temp=’null’  and $temp=empty.    
asked
5 answers
2

empty is the Mendix equivalent of null ,so you would just need to check against that. E.g. $temp = empty

A string can also be zero length and not empty so you can against that as well. E.g. $temp = ‘’’ or $temp = empty

If you also want to discount whitespace, you can wrap the check for the zero length string with the trim function. E.g. trim($temp) = ‘’ or $temp = empty

If you have Community Commons installed, you can also use the rules IsEmptyString and IsNotEmptyString which wrap some of this up.

Hope this helps.

answered
1

Hi,

This is $String=empty working for me.

Regards,

Rasik.N

answered
0

Hi Nilay,

Usually I check in the decision for: $String = empty or $String = ‘’ .

This works for me, if it doesn't for you can you let us know what is going wrong/ what error you get?

Hope this helps!

answered
0

Hi,

For decisions like these, I generally use either $String=empty or $String=’’ , hope it works for you as well, as for the null part, in Mendix, empty is equivalent to null, so you can you can use $String=empty condition.

 

All the best!

answered
0

To check whether the string value is empty or not, use below expression

$StringAttributeValue ! = empty and trim($StringAttributeValue) !=’’

 

$StringAttributeValue ! = empty  – This will ensure that the string value is not empty

 

trim($StringAttributeValue) !=’’ – This will ensure that the string value is not having one or 2 character spaces

 

So if both conditions are satisfied, then above expression will return true which means String is NOT EMPTY. if any one of the condition is failing also then above expression will return false, then the string is EMPTY

answered