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

Reusing report data provider class outside of a report

(2) ShareShare
ReportReport
Posted on by 117
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:
I have the same question (0)
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,527 Super User 2025 Season 2 on at
    May be this will help
     
    public void runCostingReportToForm()
    {
        ITMCostingRepCatReportDP dp = new ITMCostingRepCatReportDP();
        dp.parmUserConnection(new UserConnection());
        // Set contract or parameters if needed
        ITMCostingRepCatReportContract contract = new ITMCostingRepCatReportContract();
        contract.parmFromDate(systemDateGet() - 30);
        contract.parmToDate(systemDateGet());
        dp.parmDataContract(contract);
        dp.processReport();
        // Now pass the temp table to a form, or bind it to a form datasource
        // Example: pass to a form via args.caller() or static method
    }
     
     
    Thanks
    Ramesh
     
    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.
  • CD-28072126-0 Profile Picture
    117 on at
    Thanks, Ramesh.
     
    It's the weekend for me now, but definitely no later than Monday I will let you know if it worked.
  • Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at
    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
    117 on at
    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?
  • CD-28072126-0 Profile Picture
    117 on at
    @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
    117 on at
    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?
     
  • Martin Dráb Profile Picture
    237,904 Most Valuable Professional on at
    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
    117 on at
    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? 
  • CD-28072126-0 Profile Picture
    117 on at
    @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. 
  • Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at
    I understand. Why not create your own class based on ITMCostingReportDP to populate a temp table and use the temp table in your form?

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
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans