How to: Override the fetch Method to Filter Data for Reports (MorphX Reporting Tools) – AX 2009

You can override the fetch method to filter the data that is displayed in a report. This override does not reduce the number of records that are returned by the query of the report. Instead it prevents some records from being sent to the final report. Each record is examined by the branching logic you add to the fetch method. Branching determines which records to give to the send method. Those records appear in the final report.
NoteNote
Do not call super() when you override the fetch method in a report.
By default, each record that is returned by the query appears in the report. To reduce the number of records returned, add range restrictions to the query. Report ranges are more efficient than overriding the fetchmethod; however, report ranges are less expressive. For information about adding ranges to queries, see Query Elements in the AOT.

The following code example loops through each record that is returned by the query. The code tests a field in each record and branches to a send method call for records that belong in the report.
In this example, the BankAccountTable table is the only data source for the report. The fetch method in the report is overridden with the following code.
public boolean fetch()
{
    boolean retCode = false;
    BankAccountTable bankAccountTableRec;
    QueryRun qrun;
    ;
    // Use the queryRun object that is associated with the
    // report; element refers to the report.
    qrun = new QueryRun(element);

    // Verify that the report dialog works.
    if (! qrun.prompt())
    {
        return retCode;
    }

    // Loop through each record from the data source query of the report.
    while (qrun.next())
    {
        // Get the BankAccountTable fields from the query record.
        bankAccountTableRec = qrun.get(TableNum(BankAccountTable));

        // Exclude ODDBANK from the visible report.
        if (bankAccountTableRec.AccountID != "ODDBANK")
            {
                // Include the current record in the report.
                element.send(bankAccountTableRec);
            }
    }
    retCode = true;

    // retCode = super(); // Do not call super() when you override the fetch method.
    return retCode;
}

No comments:

Post a Comment