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, ...
Suggested Answer

ListIterator not filter my report ssrs

(0) ShareShare
ReportReport
Posted on by 2,050

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

I have the same question (0)
  • ergun sahin Profile Picture
    8,826 Moderator on at

    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.)

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

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

  • mohammed.mqi Profile Picture
    2,050 on at

    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
    237,987 Most Valuable Professional on at

    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.

  • ergun sahin Profile Picture
    8,826 Moderator on at

    Take line 18 down two lines

  • mohammed.mqi Profile Picture
    2,050 on at

    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

  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    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,050 on at

    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,826 Moderator on at

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

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 420 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans