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, ...
Answered

Error executing code: ListIterator with parameter

(0) ShareShare
ReportReport
Posted on by 2,050

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);
    }



}

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

    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.

  • Verified answer
    Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at

    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()));
    	}
    }

  • mohammed.mqi Profile Picture
    2,050 on at

    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

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    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.

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

    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.

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 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans