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: