Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Error executing code: ListIterator with parameter

(0) ShareShare
ReportReport
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 230,458 Most Valuable Professional 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,156 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 230,458 Most Valuable Professional 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,156 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.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans