This example assumes that you have
a report with a table named
Orders that contains a
field named
Order_Amount.
This example shows how to create a summary field
that finds the largest value for the
Orders.Order_Amount
field.
Get the
DataDefController object from a
ReportClientDocument object.
DataDefController ddc = rcd.getDataDefController();
Get the list of database tables, and
find theOrders table.
Tables tables = rcd.getDatabaseController().getDatabase().getTables();
ITable customerTable = tables.findTableByAlias("Orders");
Get the list of database fields, and
find the
Order_Amount field.
Fields fields = customerTable.getDataFields();
IField orderAmountField = fields.findField("{Orders.Order_Amount}", FieldDisplayNameType.formulaName, java.util.Locale.US);
Call the
canSummarizeOn method of the
SummaryFieldController class to
test whether summaries can be calculated for the field.
SummaryFieldController sfc = ddc.getSummaryFieldController();
sfc.canSummarizeOn(orderAmountField);
Create a new
SummaryField
object.
ISummaryField summaryField = new SummaryField();
Call the
setSummarizedField method to
set the field that is being summarized.
summaryField.setSummarizedField(orderAmountField);
Call the
setOperation
method to define the type of summary operation.
summaryField.setOperation(SummaryOperation.nthLargest);
Call the
setOperationParameter method to
set the parameter value for the summary operation.
Note: You can skip this step for summary types
that do not require a parameter.
summaryField.setOperationParameter(1);
Call the
add method
of
SummaryFieldController to add
the summary to the report.
The value -1 adds the
summary to the end of the summary list.
sfc.add(-1, summaryField);
Example: Adding a summary to a report
This example shows how to calculate the largest
value of the
Orders.Order_Amount
field. The summary is added to the report footer.
public void addSummary(ReportClientDocument rcd) throws ReportSDKException
{
DataDefController ddc = rcd.getDataDefController();
Tables tables = rcd.getDatabaseController().getDatabase().getTables();
ITable customerTable = tables.findTableByAlias("Orders");
Fields fields = customerTable.getDataFields();
IField orderAmountField = fields.findField("{Orders.Order_Amount}", FieldDisplayNameType.formulaName, java.util.Locale.US);
SummaryFieldController sfc = ddc.getSummaryFieldController();
boolean canSummarizeOn = sfc.canSummarizeOn(orderAmountField);
if (canSummarizeOn)
{
ISummaryField summaryField = new SummaryField();
summaryField.setSummarizedField(orderAmountField);
summaryField.setOperation(SummaryOperation.nthLargest);
summaryField.setOperationParameter(1);
sfc.add(-1, summaryField);
}
}