Aggregate Data from a Data Store Entity and Conditionally Display in a Chart or Grid

SAIL Recipes give you an opportunity to explore different interface design patterns. To learn how to directly use SAIL recipes within your interfaces, see Adapt a SAIL Recipe to Work with My Applications.


Aggregate data from a data store entity, specifically the total number of employees in each department, to display in a pie chart.

This recipe uses an employee data structure and objects created through the Use the Write to Data Store Entity Smart Service Function on an Interface recipe. Make sure that recipes has been built first in order to see data in this recipe.

Give the user the option to view the same data as a grid.



This design pattern is not recommended for offline interfaces because reflecting immediate changes in an interface based on user interaction requires a connection to the server.

This scenario demonstrates:

  • How to use a link to switch between two different SAIL components.


  * Paginginfo is bringing back all employee data in this case and sorting by
  * department.
  local!pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: -1,
    sort: a!sortInfo(
      field: "department",
      ascending: true
  local!displayAsChart: true,
    local!datasubset: a!queryEntity(
      entity: cons!EMPLOYEE_ENTITY,
      query: a!query(
        aggregation: a!queryAggregation(aggregationColumns: {
          a!queryAggregationColumn(field: "department", isGrouping: true),
          /*Aliases should be used when creating an aggregated column*/
          a!queryAggregationColumn(field: "id", alias: "count", aggregationFunction: "COUNT"),
        pagingInfo: local!pagingInfo
     * The showWhen parameter is used here in place of the if() funciton. To 
     * properly use showWhen with the link field toggle, a local variable called
     * local!displayAsChart is set with an initial value of true. This variable
     * is passed in directly in the pie chart, but the inverse value is set on
     * gridField's showWhen. 
       series: {
           items: local!,
           expression: a!chartSeries(label: fv!item.department, data: fv!item.count)
       showWhen: local!displayAsChart
       totalCount: local!datasubset.totalCount,
       columns: {
           label: "Department",
           field: "department",
           data: index(local!, "department", null)
           label: "Total",
           field: "count",
           data: index(local!, "count", null)
       value: local!pagingInfo,
       saveInto: local!pagingInfo,
       showWhen: not(local!displayAsChart)
       labelPosition: "COLLAPSED",
       align: "CENTER",
       links: a!dynamicLink(
         label: "Show as " & if(local!displayAsChart, "Grid", "Chart"),
         value: not(local!displayAsChart),
         saveInto: local!displayAsChart

Test it out

  1. Click the "Show as grid" link. The chart will be replaced with a grid that displays the same data.
  2. Click the "Show as chart" link. The grid will be replaced with the original chart.

Notable implementation details

  • The grid and the chart use the same paging info because they are displaying the same data. For larger data sets or charts that use multiple series, you may consider using a separate paging info for the grid so that you can display the data in batches.