Retrieve the database tables from the
report, and get the first field from the first table.
Tables tables = rcd.getDatabase().getTables();
IField firstField = tables.getTable(0).getDataFields().getField(0);
Create a new field object and set the
FieldValueType and
DataSource
properties based on the first field retrieved.
IFieldObject fieldObject = new FieldObject();
fieldObject.setFieldValueType(firstField.getType());
fieldObject.setDataSource(firstField.getFormulaForm());
Set formatting options for the
FieldObject.
fieldObject.setLeft(100);
Using the
ReportDefController object,
find the section of the report that the
FieldObject
will be added to.
ReportDefController reportDefController = rcd.getReportDefController();
ISection section = reportDefController.getReportDefinition().getDetailArea().getSections().getSection(0);
Add the
FieldObject
to a section in the report using the
ReportDefController object.
reportDefController.getReportObjectController().add(fieldObject, section, 0);
Example:
This sample adds a single database field to the
page header of a report.
void addDatabaseField(ReportClientDocument rcd) throws ReportSDKException
{
Tables tables = rcd.getDatabase().getTables();
IField firstField = tables.getTable(0).getDataFields().getField(0);
IFieldObject fieldObject = new FieldObject();
fieldObject.setFieldValueType(firstField.getType());
fieldObject.setDataSource(firstField.getFormulaForm());
fieldObject.setLeft(100);
ReportDefController reportDefController = rcd.getReportDefController();
ISection section = reportDefController.getReportDefinition().getDetailArea().getSections().getSection(0);
reportDefController.getReportObjectController().add(fieldObject, section, 0);
}This list includes the classes used by the sample
code:
com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
com.crystaldecisions.sdk.occa.report.application.ReportDefController
com.crystaldecisions.sdk.occa.report.data.IField
com.crystaldecisions.sdk.occa.report.data.Tables
com.crystaldecisions.sdk.occa.report.definition.FieldObject
com.crystaldecisions.sdk.occa.report.definition.IFieldObject
com.crystaldecisions.sdk.occa.report.definition.ISection
com.crystaldecisions.sdk.occa.report.lib.ReportSDKException