Show specific reports in a read-only grid

I have two record types:

1. Asset

2. Match Report

The Assets have a one-to-many relation with the Match Report

I want to show an Asset specific grid where it shows all the Match Reports of that Asset

I have created a read-only-grid where I query that the assetId should match the match_report.asset.assetId

This only works if the Asset has a minimum of one Match Report created

If there are no match reports available linked to the asset, the query will fetch all match reports from all assets and show them in the grid.

Can someone help me to make sure the grid is empty if there are no match reports available? 

This is my query in expression: 

a!queryLogicalExpression(
  operator: "AND",
  filters: {
    a!queryFilter(
      field: "asset.assetId",
      operator: "=",
      value: ri!AM_Match_Report.asset.assetId
    )
  },
  ignoreFiltersWithEmptyValues: true
)

  Discussion posts and replies are publicly visible

  • It looks lilke "ignoreFiltersWithEmptyValues: true" is causiing the query to return all "Match Reports".  What variable are you storing the selected assetId in from the Asset Grid?

    Can we see more code?

  • Hi Bryant, I have tried setting "ignoreFiltersWithEmptyValues" to false. This is the error I am getting: 

    Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!gridField [line 2]: Expression evaluation error at function a!queryLogicalExpression [line 34]: The a!queryFilter function has an invalid value for the “value” parameter. When the value of “operator” is “=” “value” must not be null or empty.

    The selected assetId is coming from the Asset that the user has selected to view the match reports on

  • How are you saving the selected asset id in the Asset grid?

  • I am not sure if i get your quetsion. Via rule input? The interface opens on another page of the record type

  • It still seems like the query is ignoring the filter, which means it will return all entries in the DB.  Which means in that case you do not want the query to run at all.

  • You probably need to put an if() statement around the entire query. What you want to happen is that you should only query IF there is an asset ID to filter on. Otherwise, you should just return nothing. So, you could set up a query like this to define the data for your grid:

    if(
      isnull(ri!AM_Match_Report.asset.assetId),
      null,
      a!queryEntity(
        entity: cons!YOUR_CONSTANT_HERE,
        query: a!query(
          pagingInfo: a!pagingInfo(
            startIndex: 1,
            batchSize: 10
          ),
          logicalExpression: a!queryLogicalExpression(
            operator: "AND",
            filters: {
              a!queryFilter(
                field: "asset.assetId",
                operator: "=",
                value: ri!AM_Match_Report.asset.assetId
              )
            },
            ignoreFiltersWithEmptyValues: true
          )
        )
      )
    )

    I'm not sure how you are actually using this in your grid, so it's possible the null on line 3 is not correct in your scenario - however, you can replace that with other things (e.g. todatasubset({}) if you want it to return a blank datasubset for your grid).

  • Hi Peter, thanks for your answer. Also not working unfortunately. Since the assetId is never NULL. I can not imagine this should be very difficult to achieve.. This should be basic functionality right? Am I just overcomplicating it?

  • 0
    Appian Employee
    in reply to Ozin

    Yeah something isn't quite adding up. Did you try running the query separate (like directly in an expression rule) and trying different inputs to make sure it works? I'm also confused about the value in the filter expression you gave above. This looks like it's coming from a rule input for Match_Report. However, shouldn't this come from an Asset rule input if you're display the corresponding match reports for the given asset?

  • 0
    Certified Lead Developer
    in reply to Ozin

    Hi Ozin,

    Peter's suggestion should have worked. To better understand your use case, can you share the entire code of your interface and QE expression?

  • Hi, 

    This is the interface expression:

    {
      a!gridField(
        label: "Read-only Grid",
        labelPosition: "ABOVE",
        data: a!queryEntity(
          entity: cons!AM_POINTER_TO_MATCH_REPORT_ENTITY,
          query: a!query(
            selection: a!querySelection(
              columns: {
                a!queryColumn(
                  field: "matchReportId"
                ),
                a!queryColumn(
                  field: "match"
                ),
                a!queryColumn(
                  field: "date"
                ),
                a!queryColumn(
                  field: "link"
                ),
                a!queryColumn(
                  field: "comment"
                ),
                a!queryColumn(
                  field: "matchDetails"
                )
              }
            ),
            logicalExpression: a!queryLogicalExpression(
              operator: "AND",
              filters: {
                a!queryFilter(
                  field: "asset.assetId",
                  operator: "=",
                  value: ri!AM_Match_Report.asset.assetId
                )
              },
              ignoreFiltersWithEmptyValues: true
            ),
            pagingInfo: fv!pagingInfo
          ),
          fetchTotalCount: true
        ),
        columns: {
          a!gridColumn(
            label: "Match Report Id",
            sortField: "matchReportId",
            value: fv!row.matchReportId,
            align: "END"
          ),
          a!gridColumn(
            label: "Match",
            sortField: "match",
            value: fv!row.match
          ),
          a!gridColumn(
            label: "Date",
            sortField: "date",
            value: fv!row.date,
            align: "END"
          ),
          a!gridColumn(
            label: "Link",
            sortField: "link",
            value: fv!row.link,
            align: "END"
          ),
          a!gridColumn(
            label: "Comment",
            sortField: "comment",
            value: fv!row.comment
          ),
          a!gridColumn(
            label: "Match Details",
            sortField: "matchDetails",
            value: fv!row.matchDetails
          )
        },
        validations: {}
      )
    }

    This is the interface rule in the record type:

    rule!AM_AssetPerformance(
      rule!AM_GetReportById(
        rf!assetId
      )
    )

    This is the AM_GetReportById code:

    a!queryEntity(
      entity: cons!AM_POINTER_TO_MATCH_REPORT_ENTITY,
      query: a!query(
        logicalExpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "asset.assetId",
              operator: "=",
              value: ri!id
            )
          },
          ignoreFiltersWithEmptyValues: true
        ),
        pagingInfo: a!pagingInfo(
          startIndex: 1,
          batchSize: 50
        )
      ),
      fetchTotalCount: false
    )
    .data