Is there a way I can filter the data that I bring in as a part of each grid expression?

Greetings. I have a question on how to. I have examined the Grid Tutorial, and have constructed a report with a grid that pulls records from my database. I have a record type constant that retrieves my data, and an expression rule that brings the particular data into the grid. This all works well. The problem that I have is that I want to bring back about 40 different grids depending on business units and data that I'm returning. Is there a way I can filter the data that I bring in as a part of each grid expression, or do I have to set up a record type to filter for each of these different data values, then a rule and a constant? There are two different data series for 3 business lines, so it could go up to 108 different record/rule/constant combinations....

OriginalPostID-75936

OriginalPostID-75936

  Discussion posts and replies are publicly visible

  • Take a look at the queryrecord() expression, it allows you to perform a Query on a Record (Process, Entity or Service backed) and apply filters or aggregations. You can do these as part of the data retrieval function.
  • Thanks Jorge. Is there an example of one that I can look at? queryrecord() leads me to query, which says that there is a filter logicalExpression|filter|search but I would like to see an example of how to apply it.
  • Here's some documentation I created for creating a Grid using Queryrecord(). It leverages many of the rules in the Appian Common Objects Library:

    How to quickly generate a SAIL Paging Grid using queryrecord()

    *Create the "data" rule

    The first step is to create an expression rule that defines the Data that will feed the paging grid:
    1. If you don't have it already, create a constant with your Record Type.
    2. Create a new expression Rule using the queryrecord() expression and the APN_querySelection() rule. It should take a single pagingInfo parameter of Any Type
    3. In the APN_querySelection() rule, for the fields parameter, include a Text Array of all the fields you want in your grid. The field names must match exactly to the ones defined in the Record.

    Example:
    Rule Name: CRT_customerBasicData:
    Description: Retrieves basic data for customers (doesn't include contact or location info)
    Parameters: pagingInfo - Any Type
    Definition:
    =queryrecord(
    recordType:cons!CRT_RECORD_TYPE_CUSTOMER,
    query: rule!APN_querySelection(
    fields: {"legalName","region","industry","sinceDt","licenseRevenue","servicesRevenue","status"},
    pagingInfo: ri!pagingInfo
    )
    )
  • Create The Grid Definition Rule

    Once we know where the data is coming from, since the queryrecord() already returns a dataset, all we need is to call the APN_uiPagingGridAutoColumns:

    1. Create an expression rule using load() to reuse the paging definition and the APN_uiPagingGridAutoColumns rule
    2. Label for the Grid if you want
    3. For dataSubset, use the rule created in the previous step
    4. Under Column Labels, enter an array of Column Names. They should correspong to the fields in the data rule
    5. Under Column Fields, enter the same fields as in the data expression
    6. Define the paging info to a value that makes sense, such as 5 or 10

    Example:
    Rule Name: CRT_customerBasicPagingGrid
    Description: Definition of a SAIL Paging grid for Basic Customer Data
    Parameters: None
    Definition:
    =load(
    local!basicPagingInfo: rule!APN_pagingInfo(batchSize: 5),
    rule!APN_uiPagingGridAutoColumns(
    label: "Current Customers",
    dataSubset: rule!CRT_customerBasicData(local!basicPagingInfo),
    pagingInfo: local!basicPagingInfo,
    columnLabels: {"Legal Name", "Region", "Industry", "Since Dt", "License Revenue","Services Revenue", "Status"},
    columnFields: {"legalName","region","industry","sinceDt","licenseRevenue","servicesRevenue","status"}
    )
    )
  • Yes, that will bring the fields that I want into the grid.
    What I want to do is bring in, for example, all records of sinceDt that are in the past 30 days.
  • I'm sure that there is a filter that I can apply to the queryrecord, but I don't know how to format it into my expression.
    Which is something like:

    with(
    local!datasubset: rule!ER_SR_HOME_DATA_KTLO(
    'type!PagingInfo'(
    startIndex: 1,
    batchSize: -1,
    sort: {field: "launch", ascending: true}
    )
    ),
    'type!Grid'(
    label: "Business as Usual",
    totalCount: local!datasubset.totalCount,
    columns: {
    'type!GridTextColumn'(
    label: "Product",
    data: local!datasubset.data.site,
    alignment: "LEFT"
    ),
    'type!GridTextColumn'(
    label: "Title",
    data: local!datasubset.data.summary,
    alignment: "LEFT"
    ),
    'type!GridTextColumn'(
    label: "Phase",
    data: local!datasubset.data.phase,
    alignment: "LEFT"
    ),
    'type!GridTextColumn'(
    label: "Launch Date",
    data: local!datasubset.data.launch,
    alignment: "LEFT"
                        )
    },
    value: 'type!PagingInfo'(
    startIndex: local!datasubset.startIndex,
    batchSize: local!datasubset.batchSize
    )

    I would like to run that query and filter on launchDate to select all data in the past 30 days.
    In here somewhere:
    =queryrecord(
    recordType: cons!SR_ER_HOME_LAST30,
    query: 'type!Query'(
    'selection|aggregation': 'type!Aggregation'(
    columns: {
    'type!AggregationColumn'(
    field: "launchDate",
    alias: "launch",
    visible: true,
    isGrouping: true
    ),
    'type!AggregationColumn'(
    field: "site",
    alias: "site",
    visible: true,
    isGrouping: true
    ), 'type!AggregationColumn'(
    field: "summary",
    alias: "summary",
    visible: true,
    isGrouping: true
    ), 'type!AggregationColumn'(
    field: "theme",
    alias: "theme",
    visible: true,
    isGrouping: true
    )
    }
    ),
    pagingInfo: 'type!PagingInfo'(startIndex: 1, batchSize: -1, sort: {field:
    "launch", ascending: true})
    )
    )
  • Thanks to Avneet Mathur we have a solution that works excellently. Thanks for all of the suggestions.