Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Error executing code: ListIterator with parameter

Posted on by 2,016

Greeting everyon 

i've created a new report and it's works fine

but when i didn't put parameter it's give me error

pastedimage1615278414799v1.png

and that parameter i want it not requires to apply my report

here the error showing me how can i ignore that parameter if null? 

pastedimage1615278510399v2.png

[SysEntryPointAttribute]
public void processReport()
{
    Query                   query;
    QueryRun                queryRun;
    AssetGroup              assetGroup;
    QueryBuildDataSource    qbdsAssetGroup;
    ListIterator            groupListIterator;

    date fromDate,toDate;


    contract = this.parmDataContract() as FixedAssetTransReportContract;

    fromDate=contract.parmFromDate();
    toDate=contract.parmToDate();


     groupListIterator = new ListIterator(contract.parmFixedAssetGroup());
    query = new Query(queryStr(QueryAssetGroup));
    qbdsAssetGroup = query.dataSourceTable(tableNum(AssetGroup));

    while(groupListIterator.more())
    {
        qbdsAssetGroup.addRange(
            fieldNum(AssetGroup, GroupId)).value(groupListIterator.value());
        groupListIterator.next();
    }

    queryRun = new QueryRun(query);

    while(queryRun.next())
    {
        assetGroup = queryRun.get(tableNum(assetGroup));
        this.populateTmpTable(assetGroup.GroupId,fromDate,fromDate);
    }



}

  • Martin Dráb Profile Picture
    Martin Dráb 225,588 Super User on at
    RE: Error executing code: ListIterator with parameter

    All right, so it seems that your problem was indeed in parmFixedAssetGroup() returning null. Another solution of this problem is having the list always initialized - then the caller code doesn't have to worry about this validation and you won't get errors like this.

    By the way, what is your reason for preferring iterators? Enumerators require less code and they - unlike iterators - work even if you iterate a collection on another tier. That's why they're the recommended choice.

    Having many collections in a contract isn't any problem from technical point of view. If it works for your business requirements and user experience, then it's fine.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Error executing code: ListIterator with parameter

    Yes, it's a "good way" to check whether your list is null before assigning it to iterator or enumerator. You should always do it so it's a good approach, no matter if you have 1 or 100 parameters / lists.

  • mohammed.mqi Profile Picture
    mohammed.mqi 2,016 on at
    RE: Error executing code: ListIterator with parameter

    thanks for replay

    i solved by also this way

     if(contract.parmFixedAssetGroup())
        {
         groupListIterator = new ListIterator(contract.parmFixedAssetGroup());
        query = new Query(queryStr(QueryAssetGroup));
        qbdsAssetGroup = query.dataSourceTable(tableNum(AssetGroup));
    
        while(groupListIterator.more())
        {
            qbdsAssetGroup.addRange(
                fieldNum(AssetGroup, GroupId)).value(groupListIterator.value());
            groupListIterator.next();
        }
        }
    
        else
        {
            query = new Query(queryStr(QueryAssetGroup));
        }

    do you think that is also good way if i have many parameters with ListIterator

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 225,588 Super User on at
    RE: Error executing code: ListIterator with parameter

    Also, what if you use ListEnumerator instead of ListIterator? That's the usual way. For example:

    ListEnumerator enumerator;
    
    if (contract.parmFixedAssetGroup())
    {
    	enumerator = contract.parmFixedAssetGroup().getEnumerator();
    	while (enumerator.moveNext())
    	{
    		qbdsAssetGroup.addRange(fieldNum(AssetGroup, GroupId)).value(queryValue(enumerator.current()));
    	}
    }

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Error executing code: ListIterator with parameter

    You need to check what contract.parmFixedAssetGroup() returns before trying to assign it to ListIterator.

    If you have null instead of a list, you should not try to initialize ListIterator.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,989 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,588 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans