AggregateFields
AggregateFields are ADITO models for aggregating EntityField values, for example by
- counting datasets, for example via an ID column,
- summing values, or
- returning minimum, maximum, or average values.
In most cases, aggregations are used together with grouping.
One straightforward example is the Offer context in the ADITO xRM project. The following sections use this context to explain both the client-side appearance and the Designer-side configuration of AggregateFields.
Appearance
In the client, open the Offer context from menu group Sales. In the FilterView of this context (OfferFilter_view), use the view selection button in the upper-right corner. Among the available ViewTemplates, three variants of type DynamicMultiDataChart are provided. All three are column charts based on a predefined grouping by EntityField STATUS of Offer_entity in module offer, which contains values such as Checked, Open, Sent, or Won.
- Count Chart shows how many Offer datasets exist for each
STATUSvalue. - Sum Chart shows the sum of all
NETvalues for eachSTATUSvalue. - Probability Chart shows the average
PROBABILITYvalue for eachSTATUSvalue.
DynamicMultiDataChart is only one possible target. AggregateFields can also be used in other ViewTemplate types and in Consumers. See Properties allowing AggregateFields.
Configuration
When using DbRecordContainer
To configure aggregation with a DbRecordContainer, proceed as follows:
- Create an EntityField and assign a
title. This field acts as the parent field of the AggregateField. InOfferFilter_view, the aggregate-related parent fields areCOUNT,NET, andPROBABILITYofOffer_entity. - Add an AggregateField to that EntityField. Right-click the EntityField and choose
New AggregateField. The dialog asks for a name and a parent field.- The default naming pattern is
<EntityField name>_aggregate, for exampleCOUNT_aggregate,NET_aggregate, orPROBABILITY_aggregate. - By default, the parent field is the EntityField to which the AggregateField is added. In most cases this setting can remain unchanged.
- The default naming pattern is
- Open the RecordContainer node, for example
db, and initialize the correspondingxxx.valueRecordFieldMapping such asCOUNT_aggregate.value. - In the "Properties" window, you can now configure the properties
recordField: Select the EntityField whose values should be aggregated. Alternatively, you can enter SQL code inexpression. If both are set, ADITO usesexpressionexclusively.aggregateType: Select the aggregation type, for exampleCOUNT,SUM,AVG,MIN, orMAX.
- Create a ViewTemplate that supports AggregateFields. See Properties allowing AggregateFields. In the example above, this is done with
DynamicMultiDataChartViewTemplates assigned toOfferFilter_view. - Set the new ViewTemplate properties:
title, for exampleSum chartchartType, in this caseCOLUMNdefaultGroupFields: Because the x-axis is determined by grouping, set the grouping field here. In the example, this isSTATUS.columns: The y-axis values come from an EntityField. In the three example charts these areCOUNT,NET, andPROBABILITY. In addition, set the corresponding AggregateField incolumns.aggregateEntityField, for exampleCOUNT_aggregate.yAxisLabel: Optionally define a label for the y-axis.
When using JDitoRecordContainer
AggregateFields can also be used with a JDitoRecordContainer. The first configuration steps are similar to the DbRecordContainer setup.
The ADITO xRM context Turnover is a useful reference for learning this setup:
- Open an ADITO xRM project that contains demo data.
- In menu group
Sales, openSales forecast. This opens the context that appears asTurnoverin the Designer. - Review the different ViewTemplates in the
GroupLayoutof the FilterViewTurnoverDynamicMultiDataChart_view. - In the Designer, inspect the
Turnovercontext and the ViewTemplates assigned toTurnoverDynamicMultiDataChart_view. - Read the
documentationproperty ofTurnover_entityin module revenue. - Review the Entity configuration, including EntityFields, RecordFieldMappings, and AggregateFields.
- Examine the involved
JDitoRecordContainersin detail. TheircontentProcessimplementations use a specific grouping and result format.- The
contentProcessof RecordContainerjditocontains detailed inline documentation. - It is also useful to inspect
jditoDynamicMultiDataChartand itscontentProcess.
- The
displayValueProcess of an AggregateField
To format an AggregateField, you need to use the displayValueProcess.
AggregateFields currently can only be formatted by using the displayValueProcess. In the RecordFieldMappings, a displayValue.expression property exists, but as the system builds the aggregate from the return of the expression, it is not possible to use it for extra formatting or adding further elements to the result of the aggregate function.
import { result, vars } from "@aditosoftware/jdito-types";
result.string("#: " + vars.get("$this.value"))
Usage in filter
If you want to use an AggregateField in a filter, set isFilterable of the parent field's RecordFieldMapping to true. The field then appears in the filter component on the right side of the FilterView using the title of the parent field, not the title of the AggregateField itself.
AggregateFields can also be used in filterConditionProcess. In that context, the following variables are relevant:
$local.isAggregateCondition:trueif the current condition is based on an AggregateField$local.conditionHaving: The condition that must be inserted into the subselect when a FilterExtension is triggered by an aggregation field$local.columnPlaceholder: The placeholder value used when filtering by attributes and resolving the correct column name
Usage in Consumer
AggregateFields can also be used in a Consumer via the properties
lookupIdFieldtargetContextFieldtargetIdFieldsortingField
If you need to display two aggregations in the same Entity, use a second Consumer.
Properties allowing AggregateFields
AggregateFields can be specified in various properties of the following ADITO models:
- ViewTemplates
- properties
entityFieldandcolumns/fields:- Actions
- CardTable
- DynamicMultiDataChart
- DynamicSingleDataChart
- Gantt
- Generic
- GenericMultiple
- ScoreCard
- Table
- TitledList
- TreeTable
- ActionList: properties
titleField,descriptionField,iconField
- properties
- Consumer: properties
lookupIdField,targetContextField,targetIdField,sortingField