1. Home
  2. Administrators
  3. Formulas
  4. JavaScript functions
  5. detailAgg function – Compose a field from the data of a detail tab

detailAgg function – Compose a field from the data of a detail tab

This functionality allows you to compose a field using the data from one or more of its child documents in one of its detail tabs.

For example, a document from the Country category has several documents from the Province category associated with it. And if we want to create a field in Country that lists the data of all its Provinces, we will use the formula:

Document.detailAgg(List_field, Fields, Separator, Order, [Condición], [Top], [Agrupación])

Where:

Field_list : is the name of the dropdown list in the child category, where the document of the parent category is selected. Its syntax is that of a tag type:< @CodeCategory:Group:Field> . For example, in Country, we can combine the data of your Provinces as follows:

'<@PRV:Data:Country>'

Fields : is the text string between quotes with the field labels that we want to extract from each child document. These labels are of the same type as the Field_list. In this case they can be combined with fixed text as we see in the example:

'Province:< @PRV:Properties:Name> Area m2:< @PRV:Data:Surface> '

Separator : is a text string between quotes that will separate the data of each document. You can include \n for line breaks or \t for tabs. For example:

'\n'

Order : is an ordering text string. Indicates on which field or fields we want to order the results. The syntax must include the name of one or more fields separated by commas. Behind each of them we can specify the ASC or DESC clause to indicate the order. For example:

'< @PRV:Properties:Name> ASC,< @PRV:Data:Surface> DESC'

Condition : This is an optional parameter with a T-SQL condition text string of the same type used in dropdown lists. It allows us to filter the results of the aggregate. For example, to filter Provinces starting only with Al :

"<@PRV:Properties:Name> LIKE 'A%l'"

Top: is an optional parameter with a number indicating the maximum number of records to return.

Grouping: is an optional parameter that indicates the field by which you want to group. When using groupings it is possible to indicate the aggregate functions:

  • COUNT(*) to return the number of elements
  • SUM(field) to get the sum of numeric and currency fields
  • AVG(field) to get the sum of numeric and currency fields
  • MAX(field) to get the maximum value of the field
  • MIN(field) to obtain the minimum value of the field

It is important to know that when using groupers, only fields that are already included in the Fields parameter can be used in the Order parameter.

The final formula (without grouping) from a field of the Country category called Provinces starting with Al and its area is as follows:

Document.detailAgg('<@PRV:Data:Country>', 'Province: <@PRV:Properties:Name>, Area km2: <@PRV:Data:Surface>', '\n', '<@PRV:Properties:Name> ASC', "<@PRV:Properties:Name> LIKE 'Al%'")

Therefore, for the Country Spain, the Provinces that begin with Al field and its area would show the following value:

Province: Alava, Surface area km2: 3,037
Province: Albacete, Area km2: 14.926
Province: Alicante, Surface km2: 5.817
Province: Almería, Surface area km2: 8.775

A variant with groupings of provinces could be as:

Document.detailAgg('<@PRV:Data:Country>', 'Provinces: COUNT(*), Total area: SUM(<PRV:Data:Inhabitants>)', '\n',null, "<@PRV:Properties:Name> LIKE 'Al%'",null,"<@PRV:Properties:Name>")

Therefore, for the Country Spain, the Provinces that begin with Al field and its area would show the following value:

Provinces: 4, Total area: 32.155
Updated on 21 de November de 2023
Was this article helpful?

Related Articles