Skip to main content

Notifications

Community site session details

Community site session details

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

Reusing report data provider class outside of a report

(0) ShareShare
ReportReport
Posted on by 111
I want to display the data for a report in a form instead. My idea was to call the processReport method of the report data provider class to populate the report's temp table:
ITMTmpCostReportTable tmp;
ITMCostingRepCatReportDP icrc=new ITMCostingRepCatReportDP();
icrc.processReport();
I would bind the form's data source to the temp table, which I am expecting to have the same data as if I ran the report. However, I get a run time error:
public class ITMCostingReportDP extends SrsReportDataProviderPreProcessTempDB
{
    public void processReport()
    {
        Query query;
        QueryRun queryRun;

        // 'The setConnection function was called with an invalid argument.'
        tmpShipCostReportTable.setConnection(this.parmUserConnection());
// ...
}
this = SrsReportDataProviderPreProcessTempDB  and parmUserConnection is defined as
public abstract class SrsReportDataProviderPreProcessTempDB extends SRSReportDataProviderBase implements SrsReportDataProviderPreProcessInterface
{
    UserConnection uc;
    // ...
    public UserConnection parmUserConnection(UserConnection _userConnection = uc)
    {
        uc = _userConnection;
        return uc;
    }
    // ...
}
1. How do I initialise the user connection?
2. If I get past that, is this approach feasible? Can I use a report data provider class in this way?
Categories:
  • CD-28072126-0 Profile Picture
    111 on at
    Reusing report data provider class outside of a report
    That is what I am trying to do. Today, since I could not extend the RDP class because of various internal methods in the RDP class,  the contract class and others, I finally copied all the necessary classes and made the internal methods public.  The project compiles, but that's as far as I got. I hope to be able to actually run MyCopyDP.processReport() tonight.
  • Anton Venter Profile Picture
    19,959 Super User 2025 Season 1 on at
    Reusing report data provider class outside of a report
    I understand. Why not create your own class based on ITMCostingReportDP to populate a temp table and use the temp table in your form?
  • CD-28072126-0 Profile Picture
    111 on at
    Reusing report data provider class outside of a report
    @Anton, exporting the report to a file is an option, and it will be given to the user if this approach is infeasible. They say that they "find it easier to navigate, filter, sort and manipulate" in a form. 
  • CD-28072126-0 Profile Picture
    111 on at
    Reusing report data provider class outside of a report
    I changed it to
    var query = new Query("ITMCostingReport");
    dp.parmQuery(query);
    and got past the error. I am not certain that this is the correct query.
     
    Apart from that, my problem now is that the members of the contract class are internal, so it seems that in order to get this to work, I will have to copy the contract class, the RDP class and maybe others. 
     
    How can I see the code that executes when you print a report, including the code that executes when you click "OK" in the parameter form? 
  • Martin Dráb Profile Picture
    234,023 Most Valuable Professional on at
    Reusing report data provider class outside of a report
    You're trying to access the PurchLine data source of the query, but there isn't any. In fact, the query has no data source at all (and therefore it can't return anything), because you've assigned an empty Query instance in init().
  • CD-28072126-0 Profile Picture
    111 on at
    Reusing report data provider class outside of a report
    I'm getting closer.
     
    I copied one or two ITM classes (I couldn't inherit from them) and edited them as necessary. My form's init method now looks like this:
     
    public void init()
    {
        super();
    
        ITMTmpCostReportTable tmp;
        ITMCostingRepCatReportDP dp = new MyITMCostingRepCatReportDP();
        dp.parmUserConnection(new UserConnection());
        dp.parmDataContract(new MyITMCostingReportContractReportingCategory())
            .parmInventDimViewContract(new InventDimViewContract());
        var query = new Query();
        dp.parmQuery(query);
        dp.processReport();
        
        //  ...
    }
    The run-time error now occurs here:
    public class ITMCostingReportDP extends SrsReportDataProviderPreProcessTempDB
    {
        public void processReport()
        {
            Query query;
            QueryRun queryRun;
    
            tmpShipCostReportTable.setConnection(this.parmUserConnection());
    
            query = this.parmQuery();
    
            QueryBuildDataSource qbdsPurchLine = query.dataSourceTable(tableNum(PurchLine));
    		                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            qbdsPurchLine.addOrderByField(fieldNum(PurchLine, PurchId), SortOrder::Ascending);
            queryRun = new QueryRun(query);
            // ...
        }
        // ...
    } 
    The call to query.dataSourceTable(tableNum(PurchLine)) returns null. Going back to my form's init method, where I have
    dp.parmQuery(query);
    query is just a new Query(). How do I find out the correct way to initialise the Query object?
     
  • CD-28072126-0 Profile Picture
    111 on at
    Reusing report data provider class outside of a report
    @Anton, I am trying to reuse code that is possibly performing complicated calculations instead of reproducing that logic. What makes it not robust?
     
    I will have to get back to you on the requirements. It's my idea to try it this way, but my colleague is the one who was given this task.
  • CD-28072126-0 Profile Picture
    111 on at
    Reusing report data provider class outside of a report
    I tried it. My form's init method looks like this:
     
    public void init()
    {
        super();
    
        ITMTmpCostReportTable tmp;
        ITMCostingRepCatReportDP dp = new ITMCostingRepCatReportDP();
        dp.parmUserConnection(new UserConnection());
        dp.parmDataContract(new ITMCostingReportContractReportingCategory());
        dp.processReport();
        
        // ...
    }
    Now I am getting a new error 'Object reference not set to an instance of an object' here:
    public class ITMCostingRepCatReportDP extends ITMCostingReportDP
    {
        // ...
        protected void initParameters()
        {
            contract = this.parmDataContract() as ITMCostingReportContractReportingCategory;
     =====> inventDimParm = contract.parmInventDimViewContract().parmInventDimParm();
            // ...
         }
         // ...
    }
    The problem is that contract.parmInventDimView() returns null here. However, parmInventDimView is an internal method of the contract class so I can't call it in my form. What can I do now?
  • Anton Venter Profile Picture
    19,959 Super User 2025 Season 1 on at
    Reusing report data provider class outside of a report
    It's possible but I don't recommend it because it's not a robust solution. What are the business requirements for putting this data in a form? Why not export the report data to file?
  • CD-28072126-0 Profile Picture
    111 on at
    Reusing report data provider class outside of a report
    Thanks, Ramesh.
     
    It's the weekend for me now, but definitely no later than Monday I will let you know if it worked.

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Product updates

Dynamics 365 release plans