Search code examples
ssrs-2012dynamics-ax-2012-r2

Proforma SalesInvoice doesn't show data from all tables


In the salesInvoice ssrs Report i have added a table called carTableEquipTmp which is not there by default, which I insert into along with the other tables(SalesinvoiceTmp and SalesinvoiceHeaderFooterTmp) in SalesInvoiceDP.InsertIntoSalesInvoiceTmp().

Even though my table carTableEquipTmp is getting successfully inserted into, the data doesn't show up on the report if i print a proforma report.

If i add test values to the carTableEquipTmp table in SalesInvoiceDP.processReport() they show up on the proforma invoice, but there's no way for me to get any parameters needed to set in the correct data into the table at this point. If i stop at this point in the debugger none of the data is present because processreport() is being called from a lower level in the code.

I think it might be a problem with maybe pack/unpack or that the proforma code runs from a server instance as the code run when it is proforma is quite different.

I can see that SalesInvoiceJournalPostBase.CreateReportData() creates an instance of salesInvoiceDP

salesInvoiceDP = new SalesInvoiceDP();
salesInvoiceDP.parmDataContract(salesInvoiceContract);
salesInvoiceDP.parmUserConnection(new UserConnection(true));

salesInvoiceDP.createData();

And that this might have something to do with it... but i still cant get the data i want in the carTableEquipTmp table.

So any idea on how to make Ax 2012 accept this new table i have added as it gets inserted into just like the other tables and there seems to be no problem...

I hope you guys can help.


Solution

  • The SalesInvoice report has two data classes you need to look at for the data provider, SalesInvoiceDP and SalesInvoiceDPBase. SalesInvoiceDPBase extends SrsReportDataProviderPreProcess, so there are a couple extra steps you need to take in order to add new datasources to the report.

    In the salesInvoiceDP class, there is a method called useExistingReportData(), which re-inserts the pro-forma temp table data under a user connection, so the SrsReportDataProviderPreProcess framework will pick it up in your report. When the pro-forma process creates the report data, it doesn't insert with a user connection so it doesn't get added to the report. This method only gets called when the report is being run pro-forma.

    You will need to add your temp table to this method, and follow the pattern for the other tables, so your code will look something like this:

    //this is different from the buffer you insert your data with
    CarTableEquipTmp localCarTableEquipTmp;
    
    ...
    
    recordList = new RecordSortedList(tableNum(carTableEquipTmp));
    recordList.sortOrder(fieldNum(carTableEquipTmp, RecId));
    
    //You will need to add a field to relate your temp table 
    //to the current invoice journal, and insert it in 
    //InsertIntoSalesInvoiceTmp() if thats where you're inserting your table.
    while select localCarTableEquipTmp
        where localCarTableEquipTmp.JournalRecId == jourRecId 
    {
        recordList.ins(localCarTableEquipTmp);
    }
    
    delete_from localCarTableEquipTmp
        where localCarTableEquipTmp.JournalRecId == jourRecId;
    
    recordList.insertDatabase(this.parmUserConnection());
    

    This method re-inserts your data under the framework and deletes the original data. The data that was re-inserted will then get picked up by the framework and show in your report. If you open CarTableEquipTmp in the table browser, you will most likely see data still there from all the times you have tried running the report. This is why we have the delete_from operation after we re-insert the data. When data is inserted under a userConnection, it is automatically deleted when the report is finished

    The other method you will want to modify is SalesInvoiceDP.setTableConnections(), and you will just need to add the following line:

    CarTableEquipTmp.setConnection(this.parmUserConnection());
    

    This will set the user connection for your table when running regular (not pro-forma). You will probably want to delete the data that is stored currently in your temp table using alt+F9 from the table browser.

    Other than that it's all standard RDP stuff, but it sounds like you have that part working fine. Your temp table must be of type "Regular" for this to work.