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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

List Enumerator is null even though it should be filled

(0) ShareShare
ReportReport
Posted on by 1,552

Hi,

So in my code below, i get list2Enum is null even though list2 is filled

 List list1   = new List(Types::Class);
 ListEnumerator list1Enum;
 AAContract1    contract1;
 
  List list2   = new List(Types::Class);
 ListEnumerator list2Enum;
 AAContract2    contract2;
 

if(list1.elements()) //asume list1 is filled
{
    list1Enum = list1.getEnumerator(); //here list1Enum is filled
}
if(list1Enum)
{
    while (list1Enum.moveNext())
    {
        contract1 = list1Enum.current();
        this.doSth();

        if(sth)
        {
            list2 = contract1.Items(); //where items is a list of contract2
            if(list2.elements())
            {
                list2Enum = list2.getEnumerator(); //here list2Enum is null
            }
            if(list2Enum)
            {
                while (list2Enum.moveNext())
                {
                    contract2 = list2Enum.current();
                    this.doSth();
                }
            }
        }
}

and here is items method in contract1 class

[DataMemberAttribute,
AifCollectionTypeAttribute('_items',Types::Class,classStr(Contract2)),
AifCollectionTypeAttribute('return',Types::Class,classStr(Contract2))]
public List Items(List _items = items)
{
items= _items ;
return items;
}

I have the same question (0)
  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi junior AX,

    could you share a screenshot of your debugger, where you have placed breakpoint in line 28 of your code, and we could also see the value of variable list2? Thanks!

  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    First of all, let me simplify your code, because many things there are unnecessary. Simpler code is easier to read and debug.

    ListEnumerator list1Enum = list1.getEnumerator(); //here list1Enum is filled
    
    while (list1Enum.moveNext())
    {
    	AAContract1 contract1 = list1Enum.current();
    	this.doSth();
    
    	if (sth)
    	{
    		List list2 = contract1.Items(); //where items is a list of contract2
    		if (list2)
    		{
    			ListEnumerator list2Enum = list2.getEnumerator(); //here list2Enum is null
    			
    			while (list2Enum.moveNext())
    			{
    				AAContract2 contract2 = list2Enum.current();
    				this.doSth();
    			}
    		}
    	}
    }

    Could you please run your code in debugger and check the type and content of list2 variable?

    How did you check the value of list2Enum?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans