web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to check if list is empty string or null

(0) ShareShare
ReportReport
Posted on by 1,979

Hi,

How to check if list is empty

So if pass null or empty string to the list.. this if condition doesn't work, it still enters the if statement

If (list && list.elements() && list.empty())

How to check for null and empty string?

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    238,745 Most Valuable Professional on at

    That's correct. If you create a list and one element (e.g. containing an empty string, for example), the list is not null, elements() returns 1 and empty returns false, because the list isn't empty - it contains one element.

    If you want to check values of elements inside the list, you'll need to iterate the list and look at those elements.

    For example:

    ListEnumerator enumerator = list.getEnumerator();
    
    while (enumerator.moveNext())
    {
        if (!enumerator.current())
        {
            ...
        }
    }

  • .. Profile Picture
    1,979 on at

    Hi Martin,

    It doesn't work. If I pass "" or null

    If(!enumerator.current()) doesn't work..it enters the if statement in both cases

  • Martin Dráb Profile Picture
    238,745 Most Valuable Professional on at

    If it enters the block, it works correctly. The condition says "if the current value is empty". Maybe you overlooked the negation (! operator).

    Your question was "How to check for null and empty string?".

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 555 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 364

#3
Diego Mancassola Profile Picture

Diego Mancassola 259

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans