Welcome to MSDN Blogs Sign in | Join | Help
Adding reports 2 - simple native report

Ok, I’m back from vacation so let’s take a look at the next thing you can do with the report SDK; adding native reports. A native report is a report that will run in the Office Accounting report engine and it will be shown in the native Office Accounting report UI. This basically means that you can create your own reports that will look and work just like any other report in the product!

 

Advantages

A few of the advantages of native reports:

  • Look and feel like any other Office Accounting report.
  • Is launched in the application like any build in report.
  • You can add drilldown.
  • User customizations can be saved

Implementing INativeReportV2

Before I start explaining how you do this I just want to say it once again: You can shortcut the implementation by using the templates as mentioned in a prior post in this blog! 

You have to implement one interface to create a new native report. I will show this with a simple example.

In this example I will create a simple report listing invoices in the system.

The most important method to implement is CreateData. In this method you have to retrieve the data that you want to show in the report. In this simple example I will simply take the data from the SDK, but in many real world scenarios this is where the real code to query the data would be.

 

 

/// <summary>

/// In this method the data for the report is generated

/// If the report supports filters you will have to handle them here

/// </summary>

/// <param name="reportFilters">These are the filters that are applied to

/// the report right now</param>

/// <param name="engine">Reference to the report engine used to run the

/// report</param>

/// <returns>The data for the report</returns>

public DataView CreateData(

    IReportFiltersV2 reportFilters,

    IReportEngineV2 engine)

{

 

    ISmallBusinessInstance instance = engine.SmallBusinessInstance;

    DataView view = instance.SalesInvoices.DataView;

    return view;

}

 

Now we have the view, but we still have to define what is going into the report. This is done in the CreateDesign method. In this case I add 5 columns to the report.

 

 

/// <summary>

/// Specify the design for the report

/// </summary>

/// <param name="iReportDesign">The design object</param>

public void CreateDesign(IReportDesignV2 iReportDesign)

{

    iReportDesign.ReportHeader.ReportTitle.Text = "Hello World Invoice list";

 

    iReportDesign.ReportColumns.CreateReportColumn(

        "CustomerName",                 //Column name in the dataview

        "Customer Name",                //Caption for the column

        ReportColumnType.RowLabel,      //Column type

        ReportColumnDataType.Text);     //Data type

 

    iReportDesign.ReportColumns.CreateReportColumn(

        "FriendlyDocumentName",         //Column name in the dataview

        "Document",                     //Caption for the column

        ReportColumnType.RowLabel,      //Column type

        ReportColumnDataType.Text);     //Data type

 

    iReportDesign.ReportColumns.CreateReportColumn(

        "SubTotalAmount",               //Column name in the dataview

        "Sub Total",                    //Caption for the column

        ReportColumnType.Data,          //Column type

        ReportColumnDataType.CurrencyWithoutSymbol);  //Data type

 

    iReportDesign.ReportColumns.CreateReportColumn(

        "Balance",                      //Column name in the dataview

        "Balance",                      //Caption for the column

        ReportColumnType.Data,          //Column type

        ReportColumnDataType.CurrencyWithoutSymbol); //Data type

 

    iReportDesign.ReportColumns.CreateReportColumn(

        "DueDate",                      //Column name in the dataview

        "Due Date",                     //Caption for the column

        ReportColumnType.Data,          //Column type

        ReportColumnDataType.Date);     //Data type

 

}

 

The rest of the methods are not really needed for a simple list report…

 

 

/// <summary>

/// Add filters that this report supports.

/// </summary>

/// <param name="reportFilters">Filters collection you can add filters to</param>

public void CreateFilters(IReportFiltersV2 reportFilters)

{

    //Right now we don't have filters in this report

}

 

/// <summary>

/// This method is called when the user drills down on a row,

/// it is now up to the method to do what is needed in a drilldown situation.

/// </summary>

/// <param name="dataRow">Row that the user drilled down on</param>

public void Drilldown(DataRow dataRow,

    object formsFactory,

    IReportEngineV2 reportEngine)

{

    //Right now we don't have drilldown in this report

}

 

/// <summary>

/// This method is called when the user hover over a  record in the report.

/// </summary>

/// <returns>return true if drilldown should be enabled on the record,

/// false if not.</returns>

public bool DrilldownActive(DataRow dataRow)

{

    //Right now we don’t support drilldown in this report

    return false;

}

 

The result is a new nice little report:

 

Posted: Wednesday, December 13, 2006 2:52 AM by Jorn

Comments

nsandiman said:

Hi,

Can you kindly guide me as to how to programmatically export an IReportDocument to Excel. This is my situation: programmatically  retrieve a particular report from office accounting and export that report to excel.

Thanks.  

# April 6, 2008 1:34 PM

Jorn said:

Hi

I just added a new post to show how this is done.

Thanks for your question

# April 11, 2008 12:39 PM

Flowerchan said:

Hi, Jorn!

I m a beginner for both Microsoft Accounting & MS Visual Studio. (I mainly use Linux & other compilers for C & C++, so I am not familiar with Visual studio)  

I am trying to create an add-in report for Microsoft Office Accounting Professional 2007.

I've read your "Adding reports 1,2 and 3" couple times.

I tried to make it using the template "Native Report" because I want the report to be the same as other reports. (template from installing the Accounting SDK)

The problem is once I finished the build, I am not too sure how to import it into the Office Accounting.

I went to "File>Utilities>Add-in Manager", and tried to "install now" it gives me error about the "Strong Name driver."

Then I create an "Class Library" project and use the GAC. http://support.microsoft.com/kb/315682

Now, I have two different projects (class library & Native Report) and I don't know what to do with it.

This may seems a very stupid question, but it would help me lots because I am really stuck!

Thank you so much.

Flowerchan

# July 29, 2009 3:19 AM

Jorn said:

Hi

My guess is that you are not signing your assembly when you are building. Try to look at the properties for your solution and look under signing. Once the native report assembly is signed you should be able to add it to GAC and then use the add-in manager to add it to Office Accounting.

# July 29, 2009 5:53 AM

Flowerchan said:

Thank you!  I was able to let it recognized.

However, I have encountered another problem.

"Error: A driver is inactive or invalid"

I've read the "Creating reports that can access data in SQL", but I am still not too sure how to solve this problem.

Please help me or give me some guideline or website.

I'm also looking into Jesper's blog "Getting the SBA"  objects right now.

Thank you.

# July 29, 2009 10:11 PM

Flowerchan said:

I got it! (^-^)

I did not register my .dll correctly and once I did it then the problem goes away.

Thank you!

# July 29, 2009 10:40 PM

Flowerchan said:

Hi Jorn,

I need your help again.

I am trying to find a way to modify the existing office accounting report, Inventory Valuation, (Report>Inventory>Inventory Valuation) by adding two extra columns.  Is there a way to just edit the existing code by adding two new fields or do I have to write everything from scratch?

If I have to do it from scratch then which tables should I be look into since there are so many tables in the office accounting and they are not been reduced into 3rd normal forms.  I was wondering if there exist a table just for the inventory valuation.

Thank you.

# August 3, 2009 1:29 AM
Anonymous comments are disabled
Page view tracker