Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

ListIterator not filter my report ssrs

(0) ShareShare
ReportReport
Posted on by 2,046

Greeting everyone 

i have this report with 4 parameter 

two of them for from date and to date

and other with Multi-Select Lookup parameter

but the problem is when i apply that not filtered 

here my codes

public void processReport()
{
    CompanyInfo companyInfo;
    CustTable   custTable;
    Query                   query;
    QueryRun                queryRun;
    ListIterator            companyListIterator,custListIterator;
    QueryBuildDataSource    qbdsCompany,qbdsCust;


    date fromDate,toDate;
    List companylist,custlist;

    SalesPurchByCompanyContract  salesPurchByCompanyContract;

    contract = this.parmDataContract() as salesPurchByCompanyContract;

    fromDate=contract.parmfromDate();
    toDate=contract.parmtoDate();
    companyListIterator = new ListIterator(contract.parmSalesPurchByCompany());
    custListIterator = new ListIterator(contract.parmSalesPurchByCompany());

    while(companyListIterator.more())
{
    while(custListIterator.more())
    {
        this.populateTmpTable(companyListIterator.value(),custListIterator.value(),fromDate,toDate);
        custListIterator.next();
    }
    companyListIterator.next();
}

}

this code for populate to temp table 

public void populateTmpTable(String50 _dataarea,String255 _AccountNum,date _from,date _to)
{
    CustTable           custTable;
    CustInvoiceJour     custInvoiceJour;
    DirPartyLocation    dirPartyLocation;
    TaxRegistration     taxRegistration;

    container conCompanies = [ 'scr','shw','sh', 'mgex','mbsg','scw' ,'spr','spw','wsof','wsom','wsos','wsow'];

    while select  crossCompany
                : conCompanies
    custInvoiceJour
    where custInvoiceJour.dataAreaId ==_dataarea
    && (custInvoiceJour.InvoiceDate >= _from) && (custInvoiceJour.InvoiceDate <= _to)
        && custInvoiceJour.OrderAccount !=_AccountNum
    {
        salesPurchByCompTemp.clear();
        salesPurchByCompTemp.CompanyID=custInvoiceJour.dataAreaId;
        salesPurchByCompTemp.InvoiceDate=custInvoiceJour.InvoiceDate;
        salesPurchByCompTemp.SalesBalance=custInvoiceJour.SalesBalance;
        salesPurchByCompTemp.SumTax=custInvoiceJour.SumTax;
        salesPurchByCompTemp.InvoiceAmount=custInvoiceJour.InvoiceAmount;
        salesPurchByCompTemp.InvoiceId=custInvoiceJour.InvoiceId;
        salesPurchByCompTemp.SalesId=custInvoiceJour.SalesId;
        salesPurchByCompTemp.IDCust=custInvoiceJour.OrderAccount;
        salesPurchByCompTemp.NameCust=custInvoiceJour.InvoicingName;

        select * from custTable where custTable.AccountNum==custInvoiceJour.OrderAccount;

        select * from taxRegistration where taxRegistration.DirPartyLocation==custTable.Party;

        salesPurchByCompTemp.TaxCustome=taxRegistration.RegistrationNumber;

        salesPurchByCompTemp.insert();
    }
}

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: ListIterator not filter my report ssrs

    Don't use company but custInvoiceJour and add other ranges same query

  • mohammed.mqi Profile Picture
    2,046 on at
    RE: ListIterator not filter my report ssrs

    thanks for reply 

    i did as you said mr. ergun

    by query  and it's work fine with crosscompany 

    as you see here

    public void processReport()
    {
        CompanyInfo companyInfo;
        Query                   query;
        QueryRun                queryRun;
        ListIterator            companyListIterator,custListIterator;
        QueryBuildDataSource    qbdsCompany,qbdsCust;
    
    
        date fromDate,toDate;
    
        SalesPurchByCompanyContract  salesPurchByCompanyContract;
    
        contract = this.parmDataContract() as salesPurchByCompanyContract;
    
        fromDate=contract.parmfromDate();
        toDate=contract.parmtoDate();
    
        companyListIterator = new ListIterator(contract.parmSalesPurchByCompany());
    
        custListIterator = new ListIterator(contract.parmCustAccountList());
    
    
    
    
        query = new Query(queryStr(SalesPurchByCompany));
    
    
        qbdsCompany = query.dataSourceTable(tableNum(CompanyInfo));
    
        while(companyListIterator.more())
        {
            qbdsCompany.addRange(
                fieldNum(CompanyInfo, DataArea)).value(companyListIterator.value());
            companyListIterator.next();
        }
    
        queryRun = new QueryRun(query);
    
        while(queryRun.next())
        {
            companyInfo = queryRun.get(tableNum(companyInfo));
            this.populateTmpTable(companyInfo.DataArea,fromDate,toDate);
        }
    
    
    }

    but i have problem how about other parameter (customer)

    how can i include it with company parameter?!

    because left that one which i need to filtered too

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: ListIterator not filter my report ssrs

    Your case is not that the filter is not working but the way you use it is wrong.

    Imagine you have 3 companies, 4 customers. You run the populateTmpTable 12 times.

    So what does populateTmpTable do? It loops the table with a company-based filter. So you loop through the same company records 4 times(except some filtered records). The records in the tmp table are naturally multiplexed.

    What you need to do is to run the entire structure with a crosscompany query (I shared the example link below).

    Or while looping companies, add customers to the "while select" as a condition (this part can be the query alone to)

    docs.microsoft.com/.../cross-company-x-code-basics

  • mohammed.mqi Profile Picture
    2,046 on at
    RE: ListIterator not filter my report ssrs

    oh sorry your right 

    but only filter working only if there's one value on Multi-Select Lookup parameter 

    but if i selected multi value on Multi-Select Lookup parameter

    it's not filtered

  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: ListIterator not filter my report ssrs

    Take line 18 down two lines

  • Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    RE: ListIterator not filter my report ssrs

    The error is caused by the fact that you're trying to declare variables in the middle of a method, which isn't allowed in AX 2012.

    If you want other statements than declarations before creating enumerator, declare variables, call other things and only then assign a value to the enumerator variable.

  • mohammed.mqi Profile Picture
    2,046 on at
    RE: ListIterator not filter my report ssrs

    thanks all for reply 

    i did as you said mr.Martin  but it got error

    as you see here below 

    pastedimage1620228348756v1.png

    public void processReport()
    {
        CompanyInfo companyInfo;
        CustTable   custTable;
        Query                   query;
        QueryRun                queryRun;
        ListIterator            companyListIterator,custListIterator;
        QueryBuildDataSource    qbdsCompany,qbdsCust;
    
    
        date fromDate,toDate;
        //List companylist,custlist;
        
    
    
        SalesPurchByCompanyContract  salesPurchByCompanyContract;
    
        contract = this.parmDataContract() as salesPurchByCompanyContract;
        ListEnumerator companyEnumerator = contract.parmSalesPurchByCompany().getEnumerator();
        ListEnumerator custEnumerator = contract.parmCustAccountList().getEnumerator();
    
        fromDate=contract.parmfromDate();
        toDate=contract.parmtoDate();
        
        while(companyEnumerator.moveNext())
    {
        while(custEnumerator.moveNext())
        {
            this.populateTmpTable(companyEnumerator.current(),custEnumerator.current(),fromDate,toDate);
    
        }
    
    }
    
    }

    and how can i do it with Query as you said mr.Ergün  

    and here i have two Multi-Select Lookup parameter

  • Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    RE: ListIterator not filter my report ssrs

    You skipped a few steps in your debugging. As you see, if you just check the final resdult, you have no idea where the problem lies. You'll need more granular debugging.

    For example, put a breakpoint to populateTmpTable() and check if you're getting expected values in parameters. If not, you'll know that you must look for the problem somewhere before populateTmpTable() call. If you do, you'll know that the problem is inside populateTmpTable() and you'll continue debugging there.

    Personally, I would start by checking values of those lists direct in the contract object.

    By the way, you should use ListEnumerator rather then ListIterator. For example:

    ListEnumerator companyEnumerator = contract.parmSalesPurchByCompany().getEnumerator();
    while (companyEnumerator.moveNext())
    {
    	info(companyEnumerator.current());
    }

  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: ListIterator not filter my report ssrs

    First of all, if you use Query, you can do what you want to do much easier.

    Second, you are multiplexing Records. Company records are looping over and over (as many as custList's)

    What kind of result did you come across? (If you say that the codes I added do not affect it, we will face a different problem.)

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,095 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans